[Zope] Typecasting in DTML (or is this Python?)

Dylan Reinhardt zope@dylanreinhardt.com
18 Jul 2003 00:39:11 -0700


The bracket syntax you're using is probably not necessary in any of the
cases you're using it... it's mostly for getting names that are
determined at run time, eg:

<dtml-var "_[my_name]">

If you're hand-coding literal strings, you're probably working too hard.

Check out the % operator for string formatting.  It's particularly
useful for currency, as it is possible to specify decimal places and
other fun stuff.  Since you use the word "typecasting" I'm guessing
you're probably familiar with this operator already.

Try this for starters, replacing both tags:

<dtml-var "'%s %s For $%d' % (history1, authority, amount)">

That might not be exactly right, but should get you closer to where
you're going.

HTH,

Dylan



On Fri, 2003-07-18 at 00:06, Julian Clark wrote:
> Hello again list...
> 
> I need to typecast [amount] as a string - but only within the history string.
> in my attempt below, history finished up as....
> 
> Advertising authority number 25020030718 For $['amount']
> 
> Where I need amount to show up as the specific amount.
> 
> <dtml-call "REQUEST.set('amount',_['amount'])">
> <dtml-call "REQUEST.set('history',_['history1'] + REQUEST['authority'] + ' For $' + _.str(['amount']))">
> 
> I've tried a few variants, but not had much joy.
> 
> Any help would be fantastic... thanks in advance
> 
> Julian
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )