Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have <%inherit> allow arguments, or other easy way to override/pass values #62

sqlalchemy-bot opened this issue Oct 13, 2007 · 3 comments


Copy link

Migrated issue, originally created by Anonymous

Need a way to pass python values to the parent template. Possible solutions:

  • <%inherit> parameters e.g. <%inherit file="base.mako" args="current_tab='Settings'"/>

  • <%def> variant for values e.g. <%def name="current_tab" value="Settings" />

The current way to pass values to base template is by using a <%def>, e.g.:


<% current_tab = self.current_tab() %>
        <li ${current_tab == 'Home' and 'id="current"' or ''>Home
        <li ${current_tab == 'Settings' and 'id="current"' or ''>Settings
<%def name="current_tab()"><% return "Home" %></%def>


<%inherit file="base.mako" />
<%def name="current_tab()"><% return "Settings" %></%def>

This syntax is pretty verbose, and calling self.current_tab() can accidentally result in rendered output.

Previous requests for this feature in the mailing list:

Copy link

Michael Bayer (@zzzeek) wrote:

theres an impoverished way to do this right now, like this:

# child template


<%inherit file="base"/>

# base template
foo is ${}

it would be quite easy to put a special accessor on Namespace called attr, which searches the full inheritance tree of modules for the attribute 'foo':

foo is ${}

but ive only thought about it for 30 seconds. how does that sound ?

Copy link

Michael Bayer (@zzzeek) wrote:

self.attr is in 5cfffa2

Copy link

Changes by Michael Bayer (@zzzeek):

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

1 participant