Friday, September 21, 2012

Quick note about TAL changes on recent Plone versions

I know that using complex TAL expression on Zope Page Templates is bad and symptom of bad software architecture...
...however sometimes you have an old product that... simply works!

Only recently, with Plone 4.2, we found that something changed in ZPT language rules (don't know if this is realated to the Chameleon introduction, or Zope guys found some security issues): what is changed is how you can define TALES string expressions.

The only definition of TALES string expression I know is the one learned when I was young from the old-fashion book "Definitive Guide to Plone" (wow... we are talking of Plone 2.0!).

Roughly speaking: a string expression is something that looks like follow:
"string: statictext ${path expression} another static part"

And in the definition of path expression is possible to concatenate multiple path expressions as follow:
"context/foo/bar|context/baz"

So: in old Plone (Zope) you were able to write something like this:
"string: statictext ${context/foo/bar|context/baz} another static part"

In new Plone (Zope) versions this is not possible anymore, you'll get an explicit error (so I really think this is not a bug, but a wanted limitation):
$ must be doubled or followed by a simple path in expression

We must use only simple path expressions, no multiple set..

Fixing old code is simple: just put the path expression in a tal:define, then use the simple defined variable in string expression.

You are warned.

No comments:

Post a Comment