Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:26:15+00:00 2026-05-22T15:26:15+00:00

The mako documentation seems to hint a being able to have dynamic, optional layout

  • 0

The mako documentation seems to hint a being able to have dynamic, optional layout just before “Using Blocks” but I am having a difficult time noodling it out.cle

people = dict_cursor.fetchall()
all_possible_cols = ('Name','Birth','Gender', 'Address','City','State', ...]
user_cols = user_wants(user_id) # ('State','Gender','Name')

template.render(**locals())

How do I dynamically call the defs in the template to render the columns?

mako template

% for person in people:
<tr>
  % for col in user_cols:
    How do I dynamically call the def/block?
  % endfor
</tr>
% endfor

<%def name="Name()">    ... </%def>
<%def name="Birth()">   ... </%def>
<%def name="Gender()">  ... </%def>
<%def name="Address()"> ... </%def>
<%def name="City()">    ... </%def>
<%def name="State()">   ... </%def>

So one user could want (‘Name’,’Birth’,’Gender’), another (‘Gender’,’State’, ‘Birth’), and a third could want them all in a different order. How can I cleanly support this functionality in mako templates?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:26:15+00:00Added an answer on May 22, 2026 at 3:26 pm

    If I understand your question, something like this should work:

    <tr>
      % for col in user_cols:
        ${getattr(self, col)()}
      % endfor
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using pylons with mako as templating engine and I have a template
I periodically get this problem where all of a sudden mako is using old
I constantly get this error using mako: UnicodeEncodeError: 'ascii' codec can't encode character u'\xe0'
I'm using Mako's inheritance features to factor out common page elements, like a header
I'm using Pylons with Mako templates and I want to avoid typing this all
In Pylons I have a mako template linking to /static/resource.css . How do I
I'm using CherryPy, Mako templates, and SQLAlchemy in a web app. I'm coming from
I've been reading mako / pylons documentation and am having trouble finding good examples
I have a base.mako template with a if statement to include or not jQuery
I have the following files dummy.py #!c:/Python27/python.exe -u from mako import exceptions from mako.template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.