I'd love to extend Plone's templates as easily as I can in Django. At Chameleon level it seems easy, but the code below failed in a Plone's browser view, even though I made sure
five.pt was a dependency in my build:
import ast def uppercase_expression(string): def compiler(target, engine): uppercased = self.string.uppercase() value = ast.Str(uppercased) return [ast.Assign(targets=[target], value=value)] return compiler from chameleon import PageTemplate PageTemplate.expression_types['upper'] = uppercase_expression
In my template I have:
<div tal:content="upper:'mystring';" />
Which fails with:
Compilation failed exceptions.LookupError: Unknown expression type: u'upper'
Is extending possible/should I look somewhere else? I'm running Plone 4 but the same happens in 5.
PS: I know this simple example can be implemented with a view method, allow_module or even a simple
python: expression but template extendibility is a nice selling point and may be useful for other usecases.