Using "global" images in /root/subfolder
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> to directly access the image. For the less interesting parts <dtml-var "graphics.mail_png"> <dtml-with "graphics"> <dtml-var "mail_png"> </dtml-with> <dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "mail_png"> </dtml-with> </dtml-with> <dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "_['AName']"> </dtml-with> </dtml-with> works, but unfortunately, <dtml-var "_['AName']"> emits "mail_png" as the *text*, not the image. 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. Please be gentle and explicit. I have next to no idea about Zope and Python and am just trying to "port" an existing static web site to Zope to get started. Thanks!
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>
to directly access the image. For the less interesting parts
<dtml-var "graphics.mail_png">
<dtml-with "graphics"> <dtml-var "mail_png"> </dtml-with>
<dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "mail_png"> </dtml-with> </dtml-with>
<dtml-with "graphics"> <dtml-with "_.namespace(AName='mail_png')"> <dtml-var "_['AName']"> </dtml-with> </dtml-with>
works, but unfortunately,
<dtml-var "_['AName']">
emits "mail_png" as the *text*, not the image. 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.
try: <dtml-var "_.getitem(AName)"> Use _.getitem(var) if you want an unrendered variable. See http://www.zope.org/Documentation/How-To/AdvancedDTML for a more detailed explanation. Rik
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 ------------------------------------------
: On Tue, 19 Oct 1999 09:33:07 +0200, Martijn Pieters wrote:
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)
...
Code that would solve your problem:
<dtml-with graphics><dtml-var mail_png></dtml-with>
Alright, I am now so far that this works: /root globalImage (DTML document) <dtml-with "graphics"> <dtml-var "_.getitem(img)"> </dtml-with> /graphics mail_png link_png /content some_content (DTML document) <dtml-with "_.namespace(img='mail_png')"> <dtml-var globalImage> </dtml-with> But the way I pass the "img" property (attribute?) to the "globalImage" DTML document (simply injecting it into the document's namespace) appears to be a bit cumbersome. Is there any more straight-forward way of doing this, like passing a "parameter" to the DTML document?
On Tue, 19 Oct 1999, Stefan Hoffmeister wrote:
<dtml-with "_.namespace(img='mail_png')"> <dtml-var globalImage> </dtml-with>
But the way I pass the "img" property (attribute?) to the "globalImage" DTML document (simply injecting it into the document's namespace) appears to be a bit cumbersome. Is there any more straight-forward way of doing this, like passing a "parameter" to the DTML document?
If you want to pass the img parameter to the globalImage method, may be able to use the following form: <dtml-var "globalImage(img='mail_png')"> In this form, the globalImage method does not get passed an object to work on (this()) or the current REQUEST so a there will be a number of operations you won't be able to do (eg. call PARENTS[1]) but it shouldn't matter in this case. The alternative syntax would be: <dtml-var "globalImage(this(),REQUEST,img='mail_png')"> ___ // Zen (alias Stuart Bishop) Work: zen@cs.rmit.edu.au // E N Senior Systems Alchemist Play: zen@shangri-la.dropbear.id.au //__ Computer Science, RMIT WWW: http://www.cs.rmit.edu.au/~zen
: On Wed, 20 Oct 1999 08:03:58 +1000 (EST), Stuart 'Zen' Bishop wrote:
On Tue, 19 Oct 1999, Stefan Hoffmeister wrote:
<dtml-with "_.namespace(img='mail_png')"> <dtml-var globalImage> </dtml-with>
Unfortunately,
<dtml-var "globalImage(img='mail_png')">
does not work, although this works (thanks!):
<dtml-var "globalImage(this(),REQUEST,img='mail_png')">
Given that the content of the globalImage DTML Document is just <dtml-with "images"> <dtml-var "_.getitem(img)"> </dtml-with> why would "globalImage(img='mail_png')" [which is "nice + friendly"] fail with an "access denied to images" error? I am trying to figure out how to reduce redundancy with the help of acquisition techniques. And in my book "this(),REQUEST," is sort of redundant, albeit apparently necessary, information that has to be "created" and "maintained" - and exactly what I do want to get rid of. Sorry for being a pain :-)
On Wed, 20 Oct 1999, Stefan Hoffmeister wrote:
<dtml-var "globalImage(img='mail_png')">
does not work, although this works (thanks!):
<dtml-var "globalImage(this(),REQUEST,img='mail_png')">
Given that the content of the globalImage DTML Document is just
<dtml-with "images"> <dtml-var "_.getitem(img)"> </dtml-with>
why would "globalImage(img='mail_png')" [which is "nice + friendly"] fail with an "access denied to images" error?
I am trying to figure out how to reduce redundancy with the help of acquisition techniques. And in my book "this(),REQUEST," is sort of redundant, albeit apparently necessary, information that has to be "created" and "maintained" - and exactly what I do want to get rid of.
DTML methods require passing of 'self' to them, unlike methods in just about every other OO environment. <dtml-var globalImage> seems to be identical to <dtml-var "globalImage(this(),REQUEST)">. However, if you use the "" form, the 'self' and 'REQUEST' arguments don't default to anything sensible, as in some pathalogical cases people seem to depend on testing this()==None. There was some discussion on zope-dev recently about this, but no 'official' comments on if it is worth tidying up the syntax at the expense of breaking pathalogical (IMHO) cases :-) Of course, I probably wouldn't call these cases pathalogical if I had written any myself :-) ___ // Zen (alias Stuart Bishop) Work: zen@cs.rmit.edu.au // E N Senior Systems Alchemist Play: zen@shangri-la.dropbear.id.au //__ Computer Science, RMIT WWW: http://www.cs.rmit.edu.au/~zen
: On Wed, 20 Oct 1999 11:03:15 +1000 (EST), Stuart 'Zen' Bishop wrote:
DTML methods require passing of 'self' to them, unlike methods in just about every other OO environment.
OK, so this is what I mixed up. The problem is that the documentation does NOT make it clear that DTML Methods are fundamentally different from DTML documents in this respect, that they are, in effect, Python methods. I was assuming that the DTML Method would be inheriting this() and REQUEST (and everything else) from the "surrounding" namespace ("acquire from the outermost scope[s]" in Zope speak?)
if it is worth tidying up the syntax at the expense of breaking pathalogical (IMHO) cases :-)
If the docs were fixed I wouldn't have run into this :-)
Of course, I probably wouldn't call these cases pathalogical if I had written any myself :-)
Well, I am not terribly familiar yet with the design philosophy of Zope, but as far as I can tell, acquisition means content inheritance from all outermost scopes combined - and it might be worth-while to have translate this into DTML Method calls via *Python syntax*, too. On the other hand, there appears to be no way to discriminate between DTML method calls and External Method calls... Hmmm. One paragraph in the docs should solve this problem cleanly and consistency for all method calls - and keep the current, rather elaborate syntax - consistent across calls.
participants (4)
-
Martijn Pieters -
Rik Hoekstra -
Stefan Hoffmeister -
Stuart 'Zen' Bishop