how can I achieve dynamic namespace imports in pylons / mako?
Question
I am using pylons with mako as templating engine and I have a template which uses
<%namespace name="foo" file="../bar.html"/>
and
${foo.someFunction()}
to call someFunction(). This way it is working correctly, but now I need the file "../bar.html" to be changeable dynamically like:
<%namespace name="foo" file="${c.filename}"/>
where c.filename is set in the controller. This way it isn't working and I get the following exception:
NameError: global name 'c' is not defined
Everywhere else in the template ${c.filename} is working correctly.
Does anybody know how I can achieve this import dynamically?
Thanks in advance, ashiaka
Solution
It's working when I use:
<%namespace name="foo" file="${context['tmpl_context'].filename}"/>
respectively
<%namespace name="foo" file="${context['c'].filename}"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow