Namespace inheritance unexpected behaviour

69 views Asked by At

a.mako

<%def file="one()">
    ${ two() }
</%def>

<%def file="two()">
    two
</%def>

b.mako

<%inherit file="a.mako" />
<%def file="two()">
    overriden two
</%def>

and I want to use b.mako as an namespace like

<%namespace name="test_namespace" file="b.mako" />
${ one() }

I'm expecting overriden two but it's still two

1

There are 1 answers

0
enomad On BEST ANSWER

The trick was in self.

I should write

<%def file="one()">
    ${ self.two() }
</%def>

It is partially covered by documentation indeed

http://docs.makotemplates.org/en/latest/inheritance.html#but-what-about-defs

Where above, the title() def, because it’s a def within a def, is not part of the template’s exported namespace and will not be part of self. If the inherited template did define its own title def at the top level, it would be called, but the “default title” above is not present at all on self no matter what.