TALES wish : the "thistemplate" variable
What's behind this ? Actually, we get the "template" variable available in the TALES namespace. "template", when used in a macro, refers to the template that uses the macro, and not to the template that contains the macro. The future (if you wish it with me) "thistemplate" variable will refer to the template that contains it, whatever that template is being refered or executed. Example of use : nested macros in a widgets collection template <metal:widget metal:define-macro="basicwidget"> ... </metal:widget> ... <metal:widget metal:define-macro="extendedwidget"> ... <metal:inner metal:use-macro="thistemplate/macros/basicwidget"> </metal:widget> ... </metal:widget> Actually, if you need nested macros in the same template, you need to refer that nested macro with... <...metal:use-macro="here/thistemplateid/macros/basicwiget"> 1/ using directly "thistemplate" is more legible and maintainable. 2/ you can rename more safely the templates. 3/ you can put and use attributes in templates that contains only macros. 4/ accessing "thistemplate" would not involve the acquisition machinery to find inner resource. Thus provide the invoked resource (other macro) much faster. Any comment ? Cheers --Gilles
Gilles Lenfant wrote:
What's behind this ?
Actually, we get the "template" variable available in the TALES namespace. "template", when used in a macro, refers to the template that uses the macro, and not to the template that contains the macro.
IMHO the underlying problem is that there's no clean way to control the variables used in a macro. Macros inherit whatever variables the template happens to be using. You can usually predict what variables will be available, but you have no guarantees. You might not even get "template" or "here". We recently had a discussion about this: http://dev.zope.org/Wikis/DevSite/Proposals/MacroParameters The conclusion we came to is that we need a new kind of construct, tentatively called a "subtemplate". Subtemplates accept parameters and have full control over the variable namespace, including the "template" variable. Shane
Shane Hathaway wrote:
We recently had a discussion about this:
http://dev.zope.org/Wikis/DevSite/Proposals/MacroParameters
The conclusion we came to is that we need a new kind of construct, tentatively called a "subtemplate". Subtemplates accept parameters and have full control over the variable namespace, including the "template" variable.
I'm swinging round to the ideas behind this proposal having initially been against it. What's the status of implementation? cheers, Chris
Chris Withers wrote:
I'm swinging round to the ideas behind this proposal having initially been against it. What's the status of implementation?
Somewhere in the clouds. :-) Seriously, people seem to be in favor of it, but it's not a pressing need, so no one is working on it (that I know of.) Shane
participants (3)
-
Chris Withers -
Gilles Lenfant -
Shane Hathaway