Skip to content

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

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot

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.:

base.mako

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

hello.mako

<%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:

http://groups.google.com/group/mako-discuss/browse_thread/thread/5398cd2c3aa0a694

http://groups.google.com/group/mako-discuss/browse_thread/thread/cd01b2821a3a1a57

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions