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?
If I understand your question, something like this should work: