[Zope] dynamic format strings (was: using let and fmt)
Matt Gregory
matthew.gregory@skyleach.com
Fri, 22 Feb 2002 09:44:11 -0500
I'm pretty knew to python, so I was looking at the problem from a strictly
dtml perspective. Your solution will work nicely...
> I'm not exactly sure what kind of formatting you want to do, but you can
> do it the standard python way -
Specifically, I'm changing the links in a bunch of JavaScript arrays based
on a get method parameter defining the portlet retrieving the JavaScript.
There are possibly 8 portlets retrieving the JavaScript, so the links change
for each portlet. For that reason I wanted to be able to dynamically format
the string resulting from the portlet name and get method parameters.
----- Original Message -----
From: "Paul Erickson" <erickson@kaivo.com>
To: "Matt Gregory" <matthew.gregory@skyleach.com>
Cc: "Zope" <zope@zope.org>
Sent: Thursday, February 21, 2002 5:30 PM
Subject: Re: [Zope] dynamic format strings (was: using let and fmt)
> 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>
> >>>
> >>>
> >>>
>
>
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>