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

Julian Clark Julian.Clarke@b-online.com.au
Fri, 18 Jul 2003 17:17:48 +0800


Dylan,

Thanks for your prompt reply.
I'm only familiar with typecasting from my experience in Java (which isn't huge).
it doesn't look like you're using the % as modulus in this context. Would you mind explaining a little of the syntax or pointing me
towards a url which would have some tutorials/documentation.

The fields which I am manipulating are driven by a form (actually, a series of forms) and so the data is a little dynamic
- would this still be a suitable solution?

The solution I had worked well until I changed the amount field in the database from text to numerical (so that other queries would
operate correctly with it) at which point the history string lost its banana's because it was now dealing with a string and a float.

Thanks

Julian




----- Original Message -----
From: "Dylan Reinhardt" <zope@dylanreinhardt.com>
To: "Julian Clark" <Julian.Clarke@b-online.com.au>
Cc: "zope" <zope@zope.org>
Sent: Friday, July 18, 2003 3:39 PM
Subject: Re: [Zope] Typecasting in DTML (or is this Python?)


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 )