How to do dynamic inheritance in Mako?

29 views
Skip to first unread message

Chi

unread,
Aug 11, 2010, 10:50:01 PM8/11/10
to pylons-discuss
Instead of static inheriting the files, like this:

<%inherit file="base.mako"/>

I want to set the file names dynamically in the controller with the
context variable so that I can do this:

<%inherit file="${c.base_file}"/>

I tired but I got the "global name 'c' not defined" error.
Than I tried:

<%inherit file="${context.get('c.base_file')}"/>

But than c.base_file is evaluated to 'None' even though I have
assigned value to it in the controller.

Also, I tried to do:
<%namespace file="${c.function_file}" import="a_function"/>

I got: TemplateLookupException: Cant locate template for uri '/page/$
{c.function_file}'
so the expression inside ${} is not even evaluated...


Is it possible to use dynamic file names for mako funcions 'inherit'
and 'namespace' etc??

Thanks a lot.

Eric Rasmussen

unread,
Aug 19, 2010, 12:43:49 AM8/19/10
to pylons-...@googlegroups.com
Here's the syntax that works for me:

<%inherit file="${context.get('base_file')}"/>

And in the controller you'd have something like this:

c.base_file = '/base/index.html'

Even though the variable is named c.<variable name> in the controller, when you use context.get() you omit the "c."




--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.


Reply all
Reply to author
Forward
0 new messages