[Grok-dev] How are viewlets better than macros?
wichert at wiggy.net
Mon May 5 12:01:41 EDT 2008
Previously Sebastian Ware wrote:
> On the Grok site viewlets are explained to have "...basically the same
> purpose as a macro, but is more clean, powerful and flexible." Only
> the text fails to explain how. The example shown doesn't show much of
> this power or flexibility as far as I can tell. Where is the real
> benefit? What am I missing?
They are not 'basically the same'. The concepts are different:
- using viewlet managers you can define 'slots' in a page where things
can be inserted.
- a viewlet something that produce a bit of html (the 'thing' from the
previous point) which can be shown in a viewlet manager. A viewlet
itself does not know where its output will be included.
- you can register a viewlet for a viewlet manager. That will make its
output appear in the viewlet manager's slot. A single viewlet manager
can show many different viewlets, or none at all.
- by tweaking the registrations you can move viewlets from one viewlet manager
to another, change the ordering, hide them, add new viewlets, all
without having to touch a single line of code.
The last two are not possible with macros.
Standard viewlet managers do not support ordering. Plone has an
orderable viewletmanager in plone.app.viewletmanager. I don't know if
grok has something similar.
Wichert Akkerman <wichert at wiggy.net> It is simple to make things.
http://www.wiggy.net/ It is hard to make things simple.
More information about the Grok-dev