1. Michael Bayer
  2. mako
  3. Issues

Issues

Issue #52 new

document dynamic inheritance

guest
created an issue

the template: <%inherit file="${layout}"/>

the problem: NameError: global name 'layout' is not defined

when replacing the <%inherit %> with ${layout} the proper layout string is displayed

the solution (thanks to pjenvey): <%inherit file="${context.get('layout')}"/>

Comments (4)

  1. guest reporter

    The problem here is that:

    a) the notation is supported by include: <%include file="${layout}/> works, why shouldn't <%inherit work like this ?

    b) the docs do mention dynamic inheritance as a feature, but don't go into any details/don't give an example

    I suspect a) is for a good reason (%include is within render() but %inherit is outside of it?) -- if so it should be explained along with an example

  2. Michael Bayer repo owner
    • marked as

    `<%inherit>` is calculated outside the scope of the render callables, in a separate function. it would be possible to modify how the inherit callable is generated such that it goes through the same hoops as the render callable to figure out all requested local variables and declare them from the context, but thats an awful lot of complexity to add there. so yes id say just a short doc on "dynamic" inheritance is probably best.

  3. guest reporter

    So is <%inherit file="${context.get('layout')}"/> the correct syntax? I'm wanting to use dynamic inheritance, but there's still no mention of it in the docs

  4. Log in to comment