Personal tools
You are here: Home Documentation Tutorials Macros with Grok

Macros with Grok

This Tutorial applies to: Any version.
This Tutorial is intended for: Beginners

Macros are a way to define a chunk of presentation in one template, and share it in others. Changes to the macro are immediately reflected in all of the places, that share it.

All content on one page (useful for printing, presentation mode etc.)

  1. Introduction Macros are a way to define a chunk of presentation in one template, and share it in others. Changes to the macro are immediately reflected in all of the places, that share it.
  2. Defining a simple macro In Grok macros are defined in usual views, where the associated page templates contain `metal`-statements to define the desired macros. Macros generally are attributes of the page template wherein they are defined, but to get them rendered, we usually use views.
  3. Referencing a simple macro How to reference a simple macro?
  4. Background: how grok.View and macros interact The template attribute and the macro shortcut convention.
  5. 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:
  6. Accessing Zope3 standard macros The standard macros of Zope 3, which render also the default ZMI pages, are accessible under the view-name standard_macros and usually provide slots title, headers and body. It is good style to provide this slots with your homegrown views as well.