[z3-five] (re)using zpt macros from view page templates

Philipp von Weitershausen philipp at weitershausen.de
Mon Jan 29 23:59:55 CET 2007


On 29 Jan 2007, at 23:55 , Chris Withers wrote:
> Philipp von Weitershausen wrote:
>>> my_macro.pt
>>> -----------
>>> <html metal:define-macro="template">
>>> ...etc...
>>> <metal:x define-slot="foo"/>
>>> ...etc...
>>> </html>
>> <browser:page name="mymacro" template="my_macro.pt" ... />
>
> Okay, but what interface do I bind it to? *, so it's available on  
> all objects? It just seems a bit wasteful, a view is essentially a  
> multiadapter for a context and a request. A macro needs neither  
> context nor request, and feels a lot close to a utility to me.

It's not always about actually *using* context or request. These two  
can also serve as keys for the lookup. The skin is expressed as a  
marker interface on the request, so for different skins you could  
have different versions of the 'mymacro' view, hence different macros  
for your templates.

> I want to get it from one define place, but only be accessible  
> either from trusted code, or by people who are allowed to view it.

You don't have to do it the way I outlined it...

>> Anyway, it looks like lots of unnecessary typing. Just register  
>> the tempalte with the macro as a page and access the macro as  
>> outlined above.
>
> Well, my way wasn't much typing, but I hit a problem.
>
> <browser:page name="mymacro" template="my_macro.pt" ... /> seems to  
> have a TAL version of 1.5.
>
> Products.Five.browser.pagetemplatefile.ViewPageTemplateFile seems  
> to instantiate templates with a TAL version of 1.6.

That's hard to believe. Couldn't it be you're confusing Zope3's  
*zope.app.pagetemplate*.ViewPageTemplateFile with Five's one?

> So, if I try and use my macro from a normal Five view, I get a  
> METALError: macro 'mymacro' has incompatible version '1.6'.
>
> Why is that? How can I fix it and get them both to use the same TAL  
> version?

Use everything from Five. It works.





More information about the z3-five mailing list