Control template inheritance

39 views
Skip to first unread message

Jens Stimpfle

unread,
Jan 16, 2013, 3:21:49 PM1/16/13
to mako-d...@googlegroups.com
I have a inherited template which in turn should inherit from one of a
set of base templates

middle.mako -> base.mako
- or -
middle.mako -> base2.mako

I'd like to have the client of middle.mako decide which one to use. Is
this possible? The only thing I could achieve was

# middle.mako
<%! basetemplate = "base2.mako" %>
<%inherit file="${basetemplate}"/>

But I haven't been able to set the basetemplate variable from a client.
Example which does *not* work:

# middle.mako
## I want basetemplate to be preset somehow
<%inherit file="${basetemplate}"/>

# client.mako
## DOES NOT WORK, is not seen by middle.mako
## (because technically "<%!" is module-level)
<%! basetemplate = "base2.mako" %>
<%inherit file="middle.mako"/>


Have a nice day
Jens Stimpfle

Michael Bayer

unread,
Feb 5, 2013, 11:06:05 AM2/5/13
to mako-d...@googlegroups.com
sorry, missed this email

you can access the runtime namespace in <%inherit> by referring to "context" directly:

<%inherit file="${context['foo']}" />
> --
> You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
> To post to this group, send email to mako-d...@googlegroups.com.
> To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.
>

Reply all
Reply to author
Forward
0 new messages