2009/10/07

Faster faster - getting Chameleon up'n running on Plone 3.3

You might have heard of Chameleon, Malthe Borch's fast templating engine for Python. Very fast. I wanted to give it a shot on Plone 3.3 as the benchmarks posted by Plone nestor Hanno Schlichting were looking convincing.

Chameleon works out of the box on on Plone 4. Just include cmf.pt in your buildout. However getting it up and running on Plone 3.3.1 did not turn out well at first attempt. Luckily Malthe was helpful yesterday and found a simple way to work around an issue with the global template variables in Plone. In the main_template, replace this:
<metal:block macro="here/global_defines/macros/defines">
</metal:block>

with this:
<tal:globaldefines define="global plone_view context/@@plone;
global view nocall:view | nocall:plone_view;
foo plone_view/globalize">
</tal:globaldefines>

Malthe has posted a patch for the Plone 3.3 series that might be accepted.

After a few hours together with Chameleon I have a few observations to share so far:
  • Chameleon works! It is a clever peace of software that really speeds of page rendering.
  • Chameleon's parser is more strict than the default Zope ZPT parser. If a template is not valid XML, Chameleon throws an error. Expect to spend some time to "repair" old templates. The environment variable CHAMELEON_EAGER is helpful here. Setting it makes Chameleon spit out broken templates when Zope starts.
  • TTW editing of Zope 2 ZPT templates doesn't work. TTW editing of Zope 3 ZPT templates with plone.app.customerize does (after fixing the customerize template).
  • Old style i18n does not work (PlacelessTranslationService). That includes the main Plone translation files, so for now Chameleon is not really useful for non-english Plone sites. Any ideas of how to fix that, Hanno?
I'm looking forward to play more with Chameleon. It is good company.