[Zope] dynamic format strings (was: using let and fmt)

Paul Erickson erickson@kaivo.com
Thu, 21 Feb 2002 15:30:59 -0700


I'm not exactly sure what kind of formatting you want to do, but you can 
do it the standard python way -

<dtml-let mystring="'blah'"
  format="'%s'">
 <dtml-var expr="(format) % (mystring)">
</dtml-let>
<br>

<dtml-let myfloat="_.float('123.434343')"
  format="'%5.2f'">
 <dtml-var expr="(format) % (myfloat)">
</dtml-let>
<br>

<dtml-let myfloat="_.float('123.434343')"
  mystring="'doughnut'"
  format="'You bought a %s for $%5.2f'">
 <dtml-var expr="(format) % (mystring, myfloat)">
</dtml-let>

-Paul

Matt Gregory wrote:

>Does anyone know how to dynamically format strings in DTML?  I never got (or
>never saw) an answer to this question.  I basically want to pass the fmt
>attribute as a string varable dynamically to a method.  The method formats
>some 50 strings so I really don't want 50 dtml-if statements (not to mention
>ifelse and else statements).
>
>Thanks,
>    -Matt
>----- Original Message -----
>From: "Matt Gregory" <matthew.gregory@skyleach.com>
>To: "Zope" <zope@zope.org>
>Sent: Wednesday, February 20, 2002 3:16 PM
>Subject: Re: [Zope] using let and fmt
>
>
>>BTW/FYI it throws an ErrorType: TypeError "not all arguments converted"
>>
>>----- Original Message -----
>>From: "Matt Gregory" <matthew.gregory@skyleach.com>
>>To: "Zope" <zope@zope.org>
>>Sent: Wednesday, February 20, 2002 3:11 PM
>>Subject: [Zope] using let and fmt
>>
>>
>>>Does anyone know if it's possible to do the following and if so possibly
>>>tell me why it might throw errors?
>>>
>>><dtml-let mystring="'blah'" format="'%s'">
>>>  <dtml-var mystring fmt=format>
>>></dtml-let>
>>>
>>>
>>>