[Zope] assignment problems

Martijn Pieters mj@digicool.com
Tue, 4 Jan 2000 06:02:15 -0500


> 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 
-------------------------------------------