[ZPT] Truncating strings
Tino Wildenhain
tino at wildenhain.de
Wed Oct 22 13:32:47 EDT 2003
Hi,
Ian Bicking wrote:
> 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="">...
>
This cannot be stressed enough: dont blame ZPT for things you should
not do in ZPT. Just prepare your values outside and
use the prepared values in ZPT.
You can even do truncating in CSS :-)
Regards
Tino Wildenhain
More information about the ZPT
mailing list