AW: [Zope3-dev] use-macro in ZPTPage

Jim Fulton jim at zope.com
Mon Mar 8 09:46:44 EST 2004


Roger ineichen wrote:
> Jim Fulton wrote:
> 
>>Roger Ineichen wrote:
>>
>>>Is it possible to call use-macro in a ZPTPage (Page 
>>>Template content type)? The global "views" isn't accessible. 
>>>How can I call use-macro 
>>>like the example below?
>>>
>>><html metal:use-macro="views/standard_macros/page">
>>
>>Don't use "views". It is deprecared. Where did you
>>find out about it?
> 
> The example above is used from the normal page templates
> like the add.pt in zope.app.browser.container for to 
> get the tempalte macro of the Rotterdam skin.
> See:
> http://cvs.zope.org/Zope3/src/zope/app/browser/container/add.pt?rev=HEAD&con
> tent-type=text/vnd.viewcvs-markup
> 
> 
>>Use container:
>>
>>   metal:use-macro="container/@@standard_macros/page
> 
> 
> This doesn't work, I get the following error message
> in the textarea output if I use:
> <html metal:use-macro="container/@@standard_macros/page">
> ---
> <!-- Page Template Diagnostics
>  Macro expansion failed
>  exceptions.KeyError: 'container'
> -->
> <html metal:use-macro="container/@@standard_macros/page">
> <body>
> <div metal:fill-slot="body">
> write this in the body slot.
> </div>
> </body>
> </html>
> --- 

This is a bug. Please submit a collector entry.

Turn off macro expansion. This label is missleading. It should be
something like "expandf macros when editing".

The problem is that not enough is set up to compute the expression
when *editing*. The macro will work fine when the page is used..

> What's callable global variables of a (ZPTPage) content instance?

The usable variables are:

   - container, which is the object (folder) containing the page

   - request

   - template, which is the page

   - modules, Python modules

Plus the standard ZPT variables:

   - options, which are any keyword arguments passed when the template is called

   - args, which are any positional arguments passed when the template is called

   - nothing (aka None)



> Is the implementation the same like in Zope2?
> Do we have changes? Or is "here" supported?

here is not supported. The container variable is as in Zope 2.

> I'm confused about what's the different if I use a file
> like add.pt and register them with a directive under the name "add.html"
> and if I use the source code of the add.pt in a ZPTPage called add.html

Templates used in views are different than templates used as content.

View templates have different top-level variables:

   - no container

   - context, which is the thing being views, which is like Zope 2's here

   - view, the view object.  This is useful for accessing Python attributes
     (esp methods) defined by the view.

Jim

-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org




More information about the Zope3-dev mailing list