[Zope] String to object ID

Goodrichs [email protected]
Sun, 5 Dec 1999 01:56:28 -0500


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">

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.

>Ah.  Sorry.  Misunderstood.
>
>How about:
>
><dtml-with "images.hd">
>  <dtml-var "_.getitem(section, 1)">
></dtml-with>
>
>How many strikes do I get before I'm out?  :^)
>
>Chris McDonough     mailto:[email protected]
>Digital Creations   http://www.digicool.com
>Publishers of Zope  http://www.zope.org
>
>> -----Original Message-----
>> From: Goodrichs [mailto:[email protected]]
>> Sent: Saturday, December 04, 1999 8:13 PM
>> To: [email protected]
>> Subject: RE: [Zope] String to object ID
>>
>>
>> >One way might be to forego the use of the dtml-var tag to display the
>> >image and just do:
>> >
>> ><dtml-with "_.namespace(imagename='images.hd' + section)">
>> >   <IMG SRC="<dtml-var imagename>">
>> ></dtml-with>
>> >
>> >
>> >Chris McDonough     mailto:[email protected]
>> >Digital Creations   http://www.digicool.com
>>
>> That won't work because it only returns the string we created,
>> 'images.hd.mysection' which is not a path.
>>
>> We are trying to create a method where we can dynamicly
>> display an image
>> based on the folder the page exists in. The images are named
>> according to
>> their location within the website;
>>
>> hd = top level
>> section = sublevel
>>
>> ideally;
>> top level
>>   images
>>   mysection
>>      would have an image of 'hdmysection'
>>   yoursection
>>      would have an image of 'hdyoursection'
>>
>> I want a tag I can put in any page and display the correct
>> image without
>> having to create a new unique property in all 2000 pages/ 200 folders.
>>
>> <dtml-var myimage>
>>
>> I can create to string that matches the id of the image
>> 'images.hdmysection' but i cannot get Zope to go and fetch
>> that object.
>>
>> Did I explain that properly?
>>
>> DAve.
>>
>>
>>
>> _______________________________________________
>> Zope maillist  -  [email protected]
>> http://lists.zope.org/mailman/listinfo/zope
>>           No cross posts or HTML encoding!
>> (Related lists -
>>  http://lists.zope.org/mailman/listinfo/zope-announce
>>  http://lists.zope.org/mailman/listinfo/zope-dev )
>>