[ZPT] Truncating strings
Shane Hathaway
shane at zope.com
Thu Oct 23 19:44:31 EDT 2003
On Fri, 24 Oct 2003, Fernando Martins wrote:
> What's exactly wrong with a standard function call using a path(s) as a
> parameter:
>
> <span tal:replace="fmt.truncate(container/path/to/var, 10, more='...')">
The problem is that this mixes path expression syntax with Pythonic
syntax. Whenever you combine two syntaxes arbitrarily, the boundaries of
both syntaxes become unclear. You have to choose which syntax will
dominate or the syntax will quickly degrade.
It looks like you would prefer Python syntax to dominate. You could write
it this way:
<span tal:replace="python:
fmt.truncate(path('container/path/to/var'), 10, more='...')">
Assuming you import the name 'fmt' from somewhere, and 'fmt' has a
'truncate' method, you can already write this expression. 'path' is a
special name you can use for evaluating path expressions in Python
expressions.
Shane
More information about the ZPT
mailing list