[Grok-dev] How do I reference a common template in the statics folder?

Uli Fouquet uli at gnufix.de
Wed Jul 4 19:28:29 EDT 2007

Hi Sebastian,

On Thu, 05.07.2007, 00:32 +0200 Sebastian Ware wrote:
> I am creating a "define-macro" page template, which I have put in my  
> static directory. But how do I reference it in "use-macro" and do I  
> need to create a class for this page template?

I think you indeed should define an appropriate class (and remove your
pt from 'static', macros are not static ;-) or things become quite
difficult. The method I personally like best:

- Define a class `Master(grok.View)` in a module `macros.py`. You can 
  make sure, that the context of the class binds to all other views, 
  like this::
    from zope.interface import Interface
    import grok
    class Master(grok.View):

    You don't *need* to register a macro-template for all views, but 
    you can also write one just for views of a certain model. Use this 
    model as context then. Also you don't *have* to define the macros 
    class in its own module (although it makes your code more readable, 
    from my point of view). But, yes, you need to give an associated 

- Then, in the subdirectory `macros_templates`, create a page 
  template `master.pt` with your standard macros.

>From any other of your page templates you then can call the macros in 
`master.pt` like this::

  <html metal:use-macro="context/@@master/mypagemacro">

or similar.

I think, I have seen that method (the thing with 'Interface') first in
one of Philipps applications (nudgenudge?) and like it.

Hope that helps,


More information about the Grok-dev mailing list