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

Sebastian Ware sebastian at urbantalk.se
Thu Jul 5 04:10:15 EDT 2007


Thanks! But I am still missing something:

TraversalError: (<protoncms.protonworkflow.ProtonWorkflow object at  
0x3194d70>, 'macros')

I have created macros.py...

## macros.py
import grok
from zope.interface import Interface

class Master(grok.View):
     grok.context(Interface)
     pass

...and also...

macros_templates/master.pt

...and I have defined...

##macros_templates/master.pt
[...] metal:define-macro="admin" [...]

...and I call it with...

##my_render_template.pt
[...] metal:use-macro="context/@@macros/admin" [...]

I am probably missing something simple, but I am at a loss... :)

Mvh Sebastian

5 jul 2007 kl. 01.28 skrev Uli Fouquet:

> 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):
>         grok.context(Interface)
>
>   Sidenote:
>     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
>     `grok.View`.
>
> - 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,
>
> -- 
> Uli
>
>
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list