[ZPT] Truncating strings
Ian Bicking
ianb at colorstudy.com
Wed Oct 22 12:50:44 EDT 2003
On Tuesday, October 21, 2003, at 04:55 PM, Fred L. Drake, Jr. wrote:
> Ian Bicking writes:
>> <span tal:condition="python: len(var) > 10" tal:omit-tag="">
>> <span tal:replace="python: var[:10]">var</span>...
>> </span>
>> <span tal:condition="python: len(var) < 10" tal:omit-tag="">
>> <span tal:replace="var">var</span>
>> </span>
>
> You can do this with less crud:
>
> --------------------------------------------------------
> <tal:block define="var string:abcdefghijklmnop;
> maxlen python:10;
> toolong python:len(var) > maxlen;
> partial python:var[:maxlen]">
>
> <span tal:replace="partial"
> /><tal:span condition="toolong">...</tal:span>
>
> </tal:block>
Still... so... long... to... type...
I think ZPT is giving me RSI, with the Z SQL Methods kicking me when
I'm down. (But I feel productive when I can type at full speed for
minutes on end, practically on autopilot)
Huh... tal:block must be new though. Good to know. Saves a few stokes
off <div tal:omit-tag="">...
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the ZPT
mailing list