More dtml-in sequenceing and cocatenation
I have a statment which outputs a sequence of form checkbox string pairs, from a MySQL source: <dtml-in SQL_getMath> <input type="checkbox" name="dance_<dtml-var sequence-number>" value="1" <dtml-if expr="'math_' + _['sequence-number'] == 1"> checked </dtml-if>> </dtml-in> This does not work quite right. What i need is to cocatenate, in the dtml-if expr, the string 'math_' with the number generated by sequence number in the loop. Based on that evaluation, the checkbox is checked or not. Any ideas on how to get this working? I can't seem to make much sense of the Zope Book explanation. Harlow Pinson Indepth Learning Email: hpinson@indepthl.com Web: http://www.indepthl.com Voice: 505-994-2135 FAX: 208-475-7678
hpinson@indepthl.com wrote at 2003-6-26 17:27 -0600:
I have a statment which outputs a sequence of form checkbox string pairs, from a MySQL source:
<dtml-in SQL_getMath> <input type="checkbox" name="dance_<dtml-var sequence-number>" value="1" <dtml-if expr="'math_' + _['sequence-number'] == 1">
This does not work, because "'math_' + ..." is a string and is string is not equal to "1". You probably want computed variable access: "_['math_' + _['sequence-number']] == 1" A side note: learn about "dtml-in"s "prefix" attribute. It makes your code more readable. Dieter
Thanks Dieter. I knew it was a syntax error. I'm really close I think:
You probably want computed variable access: "_['math_' + _['sequence-number']] == 1"
Results in the Zope error: Error Type: TypeError Error Value: cannot add type "int" to string This seems odd. I thought + was the python overloaded string cocatenation symbol, i.e. 'hel'+'lo' is 'hello'? I am playing with using the python str() function, but no results yet. Any ideas? Thanks. Harlow Pinson Indepth Learning Email: hpinson@indepthl.com Web: http://www.indepthl.com Voice: 505-994-2135 FAX: 208-475-7678
Solved: To get multiple form checkboxes to load their state from a SQL generated dynamic list: <dtml-in SQL_getMath> <input type="checkbox" name="dance<dtml-var sequence-number>" value="1" <dtml-if expr="_['math' + _.str(_['sequence-number'])] == 1">checked</dtml-if>> <dtml-var standard_text><br> </dtml-in> In particular: expr="_['dance' + _.str(_['sequence-number'])] == 1" I wonder if this would be easier in ZPT. The mixing of Python and DTML tripped me up. I could not find a reference to the dtml-in 'prefix' tag, but it looks promising for this sort of application. Thanks to everyone who helped! Harlow Pinson Indepth Learning Email: hpinson@indepthl.com Web: http://www.indepthl.com Voice: 505-994-2135 FAX: 208-475-7678
participants (2)
-
Dieter Maurer -
hpinson@indepthl.com