Zope tag nesting madness!
Duncan Booth
duncan at rcp.co.uk
Mon Oct 9 04:39:40 EDT 2000
noahspurrier at my-deja.com wrote in <8rrt4i$f05$1 at nnrp1.deja.com>:
>Hello,
>
>How do I nest <dtml-var> tags inside of <dtml-in> tags?
You will probably get more comprehensive answers if you ask on the Zope
mailing list.
>
>In general I want to pass an <dtml-var> to a ZSQL Method,
>but <dtml-var> must be an INTEGER. This syntax will not work:
> <dtml-in "show_article(article_id=<dtml-var id>)">
>The manager editor will compain about this and will not even let me
>submit this change.
The expression in double quote marks is simply a Python expression with
slightly funny name lookup rules. Python knows nothing about dtml. Simply
refer to the variable by its name and all will be well:
<dtml-in "show_article(article_id=id)">
>The problem here is that I have to pass id as an INTEGER.
Since id probably has a string value, try this:
<dtml-in "show_article(article_id=_.int(id))">
>
>Here is one way, but this only works if I'm calling my
>DTML Method from a form then this syntax works:
> <dtml-in "show_article(article_id=REQUEST['id'])">
>
>But I would rather figure out how to do this in the general case.
>Do I always have the REQUEST dictionary? Can I add a value to it
>just to hack my way out of this syntax problem?
As I said above the name lookup is a bit funny. When you refer to a
variable Zope searches a lot of possible namespaces in order. Variables
created by dtml-let come first, then objects and their properties (which is
where 'id' will be matched). The last place to be searched is the REQUEST
object, and that in turn searches sub objects such as REQUEST.form.
So if you refer to a variable called id, it will pick up the value from the
id property of the current object, but REQUEST['id'] will pick up the id
variable from the REQUEST.form object. If you want to set a variable
temporarily then use <dtml-call expr="REQUEST.set('name', value)"> to add
another variable to REQUEST.form.
More information about the Python-list
mailing list