Defining ‘all-purpose’ macros¶
To define an ‘all-purpose’ macro, i.e. a macro, that can render objects of (nearly) any type and thus be accessed from any other page template, just set a very general context for your macro view:
1 2 3 4 5 | from zope.interface import Interface
import grok
class Master(grok.View):
grok.context(Interface)
|
and reference the macros of the associated pagetemplate like this:
context/@@master/macros/<macro-name>
Because the macros in Master
now are ‘bound’ (in fact their view
is bound) to Interface
and every Grok application, model or
container implements some interface, the Master
macros will be
accessible from nearly every other context. Master
promises to be
a view for every object, which implements Interface
.