[Zope] String to object ID

David Kankiewicz kankie@thegrid.net
Sat, 04 Dec 1999 23:19:39 -0800


Have you tried something like:

<dtml-var "_['string']">
<dtml-var "_[var or expr (that gets the string) + 'string']">

Goodrichs wrote:
> 
> We don't count here until I'm sure I am explaining it correctly ;^)
> 
> The line;
> <dtml-with "_.namespace(imagename='images.hd' + section)">
> 
> is where we are building a string that will match the name (or id) of the
> target image we want to display. The folder has a property called section
> that has a value of 'mysection'. We are concat'n the value of this property
> onto the end of the string 'images.hd' which we use to denote a top level
> image. So the target image we want to display in the folder 'mysection'
> would be called 'hdmysection', in the top level directory named 'images'
> 
> We want to display the image 'images.hdmydirectory'. If I use this tag;
> 
>  <dtml-var "images.hdmysection">

Something like this as a sting would become:
<dtml-var "_['images.hdmysection']">

and if you need to control the behavior of the img attributes:
<dtml-var "_['images.hdmysection'].tag(border='0', etc.)">

> 
> it works, the image displays. But... if I concatenate two strings (as in
> the above example) and try to use the result to call the image. Zope
> objects because Zope knows I'm using strings and not an object reference.
> 
> Are you familar with Frontier? We have used Frontier extensively to build
> large websites. One of the truly great things about Frontier was I could
> place any image anywhere in a website by using this code;
> 
> {imgref ("myimagename")}
> 
> and the path to that image would be built on the fly and the html inserted
> into the page. When I need to choose an image based on the location of the
> page being rendered I could build the image name on the fly like so;
> 
> {imgref ({imagename = "ThisPageTitle()" + "ThisPageId()")})}
> 
> The inside macro would expand first creating the correct image name, then
> the outer macro would expand and insert an image tag pointing to the
> correct image.
> 
> ThisPageTitle = "mypage"
> andThisPageId = "myid"
> 
> {imagename = pageTitle() + pageId())} returns "mypagemyid"
> which then will execute the macro {imgref ("mypagemyid")} and return the
> correct image tag.
> 
> SO..........   my question is this, "How do I use a string I have
> constructed on the fly, to reference a Zope path to an object, and tell
> Zope to insert that object into the web page."
> 
> Are you with me?
> 
> DAve.
> 

Did I get it?

David,
tone