[ZPT] Truncating strings

Fred L. Drake, Jr. fred at zope.com
Wed Oct 22 13:00:48 EDT 2003


Ian Bicking writes:
 > Still... so... long... to... type...

Your example is pretty long not because of TAL but because you're
dealing with two different pieces: the piece from the variable, and
the piece you only show if you did truncation.  If you drop the later,
what you have is much simpler:

    <span tal:replace="python: var[:10]" />

 > Huh... tal:block must be new though.  Good to know.  Saves a few stokes 
 > off <div tal:omit-tag="">...

That's not actually new, but may be under-documented.  You can put
*any* element in the TAL namespace (using real namespace processing in
XML mode) and have omit-tag automatically turn on.  In that case,
attributes that don't specify a namespace are also accepted for TAL.
For example, this is effectively identical to the example above:

    <tal:x content="python: var[:10]" />


  -Fred

-- 
Fred L. Drake, Jr.  <fred at zope.com>
PythonLabs at Zope Corporation



More information about the ZPT mailing list