All non-trivial templates should be associated with a view. Hence, if we could agree on an easy way to lookup, instantiate and update content providers in a view without writing any code, I think we're set. It could look like this:
class MyView(BrowserView):On class instantiation, all available content providers would be instantiated and updated such that we can call the ``render``-method directly from the template (i.e. view.header.render()).
header = ContentProvider('plone.Header')
This approach has the advantage that it's actually honoring the requirement that all content providers should be updated before they're rendered (see zope/contentprovider/tales.py:41).
Obviously, this argument doesn't apply to other kinds of expressions that one could wish to plug in. Perhaps the ``string`` expression is quite handy, but very much so only because TAL doen't allow interpolation. It could look like this:
<a href="${item.getURL()}/folder_listing">
Listing of all items in ${item.Title}
</a>
There's a pattern here. Although it may seem like there's a real need for different kinds of expressions, it's really just symptom treatment. As part of our on-going effort to lower the entry bar for Zope-development, let's keep in mind that less is often more, a notion that easily extends to complexity.
1 comments:
Hi,
I ranted while before how difficult Plone template hacking has become. I quickly investigated z3c and it looks very nice performance wise.
If you are into finding new ways to develop template handling here are some ideas which could speed up development of simple tasks greatly:
- Override simple properties of viewlets without touching Python code (template, context variables)
- Create new viewlets directly-in-template, without zcml or Python
- Magic registration of viewlet classes: no XML sit ups needed
Cheers!
Mikko
Post a Comment