sqlalchemy / mako

Mako Templates for Python
https://www.makotemplates.org
MIT License
355 stars 60 forks source link

inheritance chain argument (default values) passing problem #306

Open lv-gh opened 4 years ago

lv-gh commented 4 years ago

Maybe it's not a bug at all, but i find argument passing/inheriting in the inheritance chain to be obscure. Example:

## base.mako
<%page args="x='title',y='description'" />
<base>
    arg 'x': ${x}, arg 'y': ${y}
    <%block name="foo" />
</base>
## inheriting.mako
<%inherit file="base.mako" />
<%block name="foo">
    <title>${x}</title>
    <desc>${y}</desc>
</%block>

And two cases (first works, but second don't):

mylookup.get_template('inheriting.mako').render(x='title', y='description'))
mylookup.get_template('inheriting.mako').render())

Though args with default values are set in <%page> and are valid/visible in the inheritted template (base.mako; note inheriting (inheriting.mako<-base.mako) involved) , but not in the inheriting template and it's named blocks. I know that i could pass args to named blocks via args param explicitly, but shouldn't <%page args (default values) also be inherited? (render() supplied args are visible in all templates/contexts) In other wors: is there any posibility to set all arg default values in one place?

zzzeek commented 4 years ago

I know that i could pass args to named blocks via args param explicitly, but shouldn't <%page args (default values) also be inherited? (render() supplied args are visible in all templates/contexts)

im not really sure, but I can say those mechanics are baked in for good for the foreseeable future. they are not easy to change and Mako is not seeing active development right now.