Having done some google searches with no result and referenced again the Zope book on DTML, I assume what I am trying is either very trivial or dumb: I want to do some math in DTML, here an example: <dtml-let myCounter=0> <dtml-in expr="some_method(_['a_current_id'])"> <dtml-if checked> <dtml-call expr="myCounter=myCounter+1"> </dtml-if> </dtml-in> <dtml-if expr="myCounter>0"> DO SOMETHING! </dtml-if> </dtml-let> "some_method" returns a sequence where some items might have an attribute "checked". So while I iterate over the sequence I want to change the value of "myCounter". The code above generates Syntax Errors. I tried referencing myCounter with the underscore, no luck. Any help appreciated. If there's a web page that explains a little how to "manipulate variables using DTML", I'd be really thankful to know. Cheers Marc
EVERYONE will more than likely respond "NEVER USE DTML FOR LOGIC" and math falls into this. BUT, I still find myself doing it as it just works and unless it gets TOO complicated is easy for me to follow. That said, here is how you can do this. <dtml-call "REQUEST.set('myCounter', 0)"> # creates the myCounter variable and assigns it a value of zero <dtml-in "some_method(a_current_id)"> <dtml-if checked> # if the value of the variable received from some_method exists and evaluates to true <dtml-call "REQUEST.set('myCounter', myCounter+=1)"> # increments myCounter by one </dtml-if> </dtml-in> Now this will work <dtml-if myCounter> DO SOMETHING! </dtml-if> If you only want to see if myCounter is greater than zero then the above will evaluate to true if myCounter is anything but zero YOUR BEST BET is to do this in a Python script. I do use them more and more now and have converted much of my old DTML 'logic' to Python but we still do most of our site in dtml and zsql and python scripts. I have not tested the above but should work pretty much as is (except for the python commments) DTML rocks!! :^) Allen Marc Burgauer wrote:
Having done some google searches with no result and referenced again the Zope book on DTML, I assume what I am trying is either very trivial or dumb:
I want to do some math in DTML, here an example:
<dtml-let myCounter=0> <dtml-in expr="some_method(_['a_current_id'])">
<dtml-if checked> <dtml-call expr="myCounter=myCounter+1"> </dtml-if>
</dtml-in>
<dtml-if expr="myCounter>0">
DO SOMETHING!
</dtml-if>
</dtml-let>
"some_method" returns a sequence where some items might have an attribute "checked". So while I iterate over the sequence I want to change the value of "myCounter".
The code above generates Syntax Errors. I tried referencing myCounter with the underscore, no luck.
Any help appreciated. If there's a web page that explains a little how to "manipulate variables using DTML", I'd be really thankful to know.
Cheers
Marc
_______________________________________________ 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 )
Oops.... Just use the + not += (sorry) <dtml-call "REQUEST.set('myCounter', myCounter+1)"> # increments
----- Original Message ----- From: "Marc Burgauer" <marc@sharedbase.com>
I want to do some math in DTML, here an example:
<dtml-let myCounter=0> <dtml-in expr="some_method(_['a_current_id'])">
<dtml-if checked> <dtml-call expr="myCounter=myCounter+1"> </dtml-if>
</dtml-in>
<dtml-if expr="myCounter>0">
DO SOMETHING!
</dtml-if>
</dtml-let>
"some_method" returns a sequence where some items might have an attribute "checked". So while I iterate over the sequence I want to change the value of "myCounter".
You need to set up and manipulate the counter as follows: <dtml-call "REQUEST.set('myCounter', 0)"> <dtml-call "REQUEST.set('myCounter', myCounter+1)"> This would be much cleaner in a python script. HTH Jonathan
participants (3)
-
Allen Schmidt -
Jonathan Hobbs -
Marc Burgauer