I am trying to find a way of calling def templates determined by the data available in the context.
Edit: A simpler instance of the same question.
It is possible to emit the value of an object in the context:
# in python
ctx = Context(buffer, website='stackoverflow.com')
# in mako
<%def name="body()">
I visit ${website} all the time.
</%def>
Produces:
I visit stackoverflow.com all the time.
I would like to allow a customization of the output, based upon the data.
# in python
ctx = Context(buffer, website='stackoverflow.com', format='text')
# in mako
<%def name="body()">
I visit ${(format + '_link')(website)} all the time. <-- Made up syntax.
</%def>
<%def name='html_link(w)'>
<a href='http://${w}'>${w}</a>
</%def>
<%def name='text_link(w)'>
${w}
</%def>
Changing the format
attribute in the context should change the output from
I visit stackoverflow.com all the time.
to
I visit <a href='http://stackoverflow.com'>stackoverflow.com</a> all the time.
The made up syntax I have used in the body
def
is obviously wrong. What would I need to dynamically specify a template, and then call it?