[Zope] The Let Tag How-To?

Ben Glazer glazer@scicomp.com
Wed, 16 Feb 2000 10:21:59 -0600


On Feb 16 2000 at 4:16 AM, Daniel Yoo wrote:
> Sorry for bothering you about this, but I've been trying to go through
> your Let Tag howto.  I'm doing this on 2.1.4, and I get the feeling that
> some features have deprecated.  Your example:
>
> <dtml-let name="bob"  relation="uncle">
>   <dtml-var name> is your <dtml-var relation>
> </dtml-let>
>
>
> doesn't work for me; I have to add an additional set of quotes to make it
> work:
>
>
> <dtml-let  name="'bob'"
> 	   relation="'uncle'">
>   <dtml-var name> is your <dtml-var relation>
> </dtml-let>

This is a problem that is frequently confusing to newcomers (and oldcomers)
of Zope.  The explanation is not difficult to understand, but it takes some
time to really get used to.

There are two basic types of values you can pass to a parameter in a DTML
tag:

	1. The name of a Zope object.
	2. A Python expression.

When you specify a value without enclosing it in double-quotes, it needs to
be a resolvable Zope object.  If it's not, Zope will return an error.  When
you enclose a value within a dtml tag in double-quotes, you've implied that
you want that value to be treated as a valid Python expression.

In your given example, since "bob" is not a valid Python expression (unless
the variable "bob" is defined somewhere), Zope bombs out with an error.
However, "'bob'" is a valid expression which means, "the string 'bob'."
Zope is perfectly happy displaying strings on web pages.


> Can anyone explain what changed and why?  Quotation itself feels clumsy;
> is there any way to escape-sequence quotes?  In nested DTML/SQL
> expressions, being unable to use \" seems awkward.  Thanks for any help.

You'll probably not like this one (I think it's ugly as sin), but there is a
solution:

Use Python's built-in octal ASCII character specification notation.  A
quotation mark, which is ASCII 34 is represented as \42 (since 34 in decimal
equals 42 in octal).  So you can just stick in \42 wherever you want a
double-quote to appear in your text.


Regards,
Ben