[Zope3-Users] Standard Macros

Roger Ineichen dev at projekt01.ch
Sat Feb 10 10:53:11 EST 2007


Hi David

> Subject: [Zope3-Users] Standard Macros
> 
> Is there a way to use standard_macros in a ZPT Page added via 
> the ZMI?  In a page registered via ZCML the following METAL 
> is okay, however in a ZPT Page I receive an error regarding a 
> key error for "views".
> 
> <html metal:use-macro="views/standard_macros/page">
> 
> </html>
> 
> Any ideas?

Why not use the z3c.macro pattern? I implemented some very 
handy base patterns which make the *macro as views and mapping* 
pattern obsolate.

See:
svn//svn.zope.org/repos/main/z3c.macro

With z3c:macro, you can register macros like:

<configure
    xmlns:z3c="http://namespaces.zope.org/z3c">
  <z3c:macro
      name="title"
      template="macro.pt"
      />
</configure>

And use them like:

<tal:block define="title string:My Navigation">
  <metal:block use-macro="macro:title" />
</tal:block>

Macros can get registered on context, view and layer
which makes them very handy if you need to provide
different macros for e.g. forms etc.

There is a README.txt file in the package which
explains it in more details. See also zcml.txt
for configuration infos.

And if you like, you can register a macro as a 
IViewlet within the z3c.macroviewlet package at:
svn//svn.zope.org/repos/main/z3c.macroviewlet

Macro as viewlet sample
-----------------------
  <z3c:macroViewlet
      for="*"
      template="template.pt"
      macro="title"
      manager="z3c.skin.pagelet.ITitle"
      layer="z3c.skin.pagelet.IPageletBrowserSkin"
      />

This allows you inline definitions of macros which
is very uesfull if you like to design fully working
XHTML/ZPT templates. (without to splitt everything into
own templates). e.g.

template.pt sample (see z3c.skin.pagelet)
-----------------------------------------
<tal:block replace="structure provider:ITitle">
  <metal:block define-macro="title">
    <title>The title</title>
  </metal:block>
</tal:block>

And if it's not enough, you can take a look at 
z3c.pagelet if you need more skin simplification.

btw
The pagelet pattern was developed for split the
template and python view class into own components.
I allways like to say the template is the view and 
the python view class ist the controller if I need
to make a mapping to the MVC pattern.

Regards
Roger Ineichen
_____________________________
END OF MESSAGE


> Warm regards,
> David



More information about the Zope3-users mailing list