[Zope-dev] TALES wish : the "thistemplate" variable

Gilles Lenfant gilles@pilotsystems.net
Wed, 23 Jul 2003 19:12:34 +0200


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