RE: [Zope] assignment problems
After reading all Zope docs, I have difficulties writing simple assignment and test.
<!--#var standard_html_header-->
<dtml-let Size='big'></dtml-let> <dtml-if "Size=='big'"><h1></dtml-if> Hello. <dtml-if "Size=='big'"></h1></dtml-if>
<!--#var standard_html_footer-->
The above gives error Error Type: KeyError, Error Value: 'big'.
Two things wrong here. First, the Size variable is only visible within the scope of the let tag, so you'll have to close it _after_ the block in which you want to use it. Secondly, what comes after the = sign in the let tag, is either a Zope name (same as in <dtml-var name="xxx">), when you don't use quotes, or a python expression (same as in <dtml-var expr="xxx">) when you do use quotes. In your case, "Size='big'" is interpreted as "Size equals the python expression big", where "the python expression big" means the value of the variable named big. There's your Key Error. In order to assign the string literal 'big' to the variable Size, you'll have to use quotes around the word big, either Size='"big"', or (confirming to the official HTML way of quoting) Size="'big'". With above corrections, you're code should read: <dtml-var standard_html_header> <dtml-let Size="'big'"> <dtml-if "Size=='big'"><h1></dtml-if> Hello. <dtml-if "Size=='big'"></h1></dtml-if> </dtml-let> <dtml-var standard_html_footer> -- Martijn Pieters, Software Engineer | Digital Creations http://www.digicool.com | Creators of Zope http://www.zope.org | mailto:mj@digicool.com ICQ: 4532236 | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 -------------------------------------------
With above corrections, you're code should read:
This worked. Now, what if I need to assign again to the same variable: <dtml-let Size="'big'"> <dtml-let Size="'bi'"> <dtml-if "Size=='big'"><h1></dtml-if> Hello. <dtml-if "Size=='big'"></h1></dtml-if> </dtml-let> It complains about let tag not being closed. Do I need to nest let tags? It sounds silly... -- Milos Prudek
on 4. januar 2000 Milos Prudek wrote :
With above corrections, you're code should read:
MP> This worked. Now, what if I need to assign again to the same variable: MP> <dtml-let Size="'big'"> MP> <dtml-let Size="'bi'"> MP> <dtml-if "Size=='big'"><h1></dtml-if> MP> Hello. MP> <dtml-if "Size=='big'"></h1></dtml-if> MP> </dtml-let> MP> It complains about let tag not being closed. Do I need to nest let tags? MP> It sounds silly... from the DTML-guide : [snip] The let tag is a new tag that lets you create blocks like: <!--#in "1,2,3,4"--> <!--#let num=sequence-item index=sequence-index result="num*index"--> <!--#var num--> * <!--#var index--> = <!--#var result--> <!--#/let--> <!--#/in--> [snip] .. so your exapmle could look like this : <dtml-let Size="'big'" Size2="'bi'" Size3="'small'"> <dtml-if "Size=='big'"><h1></dtml-if> Hello. <dtml-if "Size=='big'"></h1></dtml-if> </dtml-let> -- Geir B Hansen web-developer/designer geirh@funcom.com http://www.funcom.com
.. so your exapmle could look like this :
<dtml-let Size="'big'" Size2="'bi'" Size3="'small'">
But I want to reassign different value to Size, not make additional variables. Probably Martijn Pieters has the right solution. -- Milos Prudek
Martijn Pieters wrote:
Secondly, what comes after the = sign in the let tag, is either a Zope name (same as in <dtml-var name="xxx">), when you don't use quotes, or a python expression (same as in <dtml-var expr="xxx">) when you do use quotes. In your case, "Size='big'" is interpreted as "Size equals the python expression big", where "the python expression big" means the value of the variable named big. There's your Key Error. In order to assign the string literal 'big' to the variable Size, you'll have to use quotes around the word big, either Size='"big"', or (confirming to the official HTML way of quoting) Size="'big'".
With above corrections, you're code should read:
<dtml-var standard_html_header>
<dtml-let Size="'big'"> <dtml-if "Size=='big'"><h1></dtml-if> Hello. <dtml-if "Size=='big'"></h1></dtml-if> </dtml-let>
<dtml-var standard_html_footer>
There is a small mistake. In fact, <dtml-let Size='big'> is interpreted as " Size equals the value of the variable named 'big' ", not the variable named big. And <dtml-let Size="big"> is interpreted exactly as <dtml-let Size=big>, while <dtml-let Size='"big"'> simply doesn't work. hah, it is rather tricky.
participants (4)
-
Geir B Hansen -
Martijn Pieters -
Milos Prudek -
Wei Tao