At 05:58 19/10/99 , Stefan Hoffmeister wrote:
Let's assume the following structure of a site
/root /global_images mail_png link_png
/content some_content (DTML document)
In some_content, I would like to use something to the effect of
<dtml-var mail_png>
to take advantage of the image "mapping" provided by Zope. But how can I address mail_png?
The goal is to address a few global images from any location on the site with the least amount of work possible. I am as far as
<dtml-var globalImage>
in "some_content". "globalImage" is a DTML document in /root that contains
<dtml-var graphics.mail_png>
This tries to access the object named 'graphics.mail_png', _with_ the dot in the name. All characters are considered part of the identifier, none have special meaning.
to directly access the image. For the less interesting parts
<dtml-var "graphics.mail_png">
Here you are using a python expression (you are using quotes). You are asking for the mail_png object, subobject of the graphics object. Bingo, but you are accessing the object, not calling it. Your generated output will contain a object reference, something like <Image instance at 86bbe0>.
<dtml-with "graphics"> <dtml-var "mail_png"> </dtml-with>
Watch the quotes! In between quotes, you are doing the same as with <dtml-var expr="mail_png">, so you are using a Python expression, whereas <dtml-var mail_png> or <dtml-var name=mail_png> would call it. This is an import difference. See the DTML Users Guide for more details. Code that would solve your problem: <dtml-with graphics><dtml-var mail_png></dtml-with> (the usual way. Will place a HTML IMG tag) or <dtml-var "_.str(graphics.mail_png)"> (Does the same, only more explicit) or <dtml-var "graphics.mail_png.tag()"> (Uses an alternative tag rendering method, you can pass extra attributes in, like border=0)
<dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "mail_png"> </dtml-with> </dtml-with>
This doesn't do anything but add a variable called AName to the namespace that has the string 'mail_png' for a value, which you then don't use.
<dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "_['AName']"> </dtml-with> </dtml-with>
Above code will place the string 'mail_png' in your generated output.
works, but unfortunately,
<dtml-var "_['AName']">
emits "mail_png" as the *text*, not the image.
As you discovered. _[] looks up the variable with the name given by that's in between the brackets. In this case 'AName'. AName is a variable that contains the value 'mail_png'. If you wan to look up and call mail_png this way you'll either have to do: <dtml-var "_[AName]"> or <dtml-var "_['mail_png']"> Note the lack of quotes around AName. You now don't treat is as a string literal, but as a variable whose contents are passed to _[].
IOW, I am stuck. Oh, I have no clue how to pass a parameter to the DTML document, so that I can say
<dtml-var name="globalImage(AName='mail_png')"> <dtml-var name="globalImage(AName='link_png')">
or whatever works.
You should be able to get things working now. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------