[ZPT] Truncating strings

Ian Bicking ianb at colorstudy.com
Wed Oct 22 15:36:26 EDT 2003


On Tuesday, October 21, 2003, at 04:01 PM, Ian Bicking wrote:
> How higher-level functions interact with TALES, I'm not sure... but if 
> it's more difficult, it matters much less that the formatters are easy 
> to program, compared to being easy to use.  Or maybe this is really 
> just the importing problem, because this would be just as good:
>
> <span tal:replace="structure python: formatters.truncate(var, 
> 10)">var</span>

It occurred to me that you could kind of do this right now.  Say you 
add a zpt_util folder to your Zope installation, which contains things 
like truncate.  Then in standard_template.pt, add something like:

<html metal:define-macro="page">
   <tal:block define="util container/zpt_util">
   ...
   </tal:block>
</html>

Then you can do <span tal:replace="python: util.truncate(var, 10)"/>.  
You can add all the other formatters from PythonScripts.standard as 
well, for much easier access.  From my ZPT use so far, I think this 
would be very convenient.  *But* it's also really lame, because you are 
adding this implicit object (util) to your pages through the template, 
which is an abuse of the template (if it even works?), all to save 
"container.zpt_util" instead of just "util".  (But I'd really like to 
save those 14 characters)

Anyway, a thought...

--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org




More information about the ZPT mailing list