[Zope] Examples of using the fmt attribute
Chris Withers
chrisw@nipltd.com
Wed, 30 Oct 2002 13:51:27 +0000
Sandy Donaldson wrote:
> Can anyone help me with the fmt atribute of DTML, or at least point me to
> some examples ...
ironicly, none of these are best solved with fmt ;-)
> I need to format 2001-12-31 00:00:00.00 as 31-12-2001
<dtml-var "x.strftime('%d-%m-%Y')">
> I need to format 0.00 as nothing (leave blank)
<dtml-var x null=""> (maybe)
<dtml-if x><dtml-var x></dtml-if> (definitely)
> I need to format -2,782.50 as 2,782.50 (absolute)
<dtml-if "x>0"><dtml-var x><dtml-else><dtml-var "-x"></dtml-if>
Personally, I'd recommend you get the online Zope book and learn ZPT instead.
The above examples become:
> I need to format 2001-12-31 00:00:00.00 as 31-12-2001
<tal:x content="python:x.strftime('%d-%m-%Y')">31-12-2001</tal:x>
> I need to format 0.00 as nothing (leave blank)
<tal:x content="x"
condition="x">0.00</tal:x>
> I need to format -2,782.50 as 2,782.50 (absolute)
<tal:x content="python:abs(x)">2,782.50</tal:x>
cheers,
Chris