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:chrism@digicool.com Digital Creations http://www.digicool.com Publishers of Zope http://www.zope.org
-----Original Message----- From: Goodrichs [mailto:nbd95@macconnect.com] Sent: Saturday, December 04, 1999 8:13 PM To: zope@zope.org 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:chrism@digicool.com 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 - Zope@zope.org 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 )
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:chrism@digicool.com Digital Creations http://www.digicool.com Publishers of Zope http://www.zope.org
-----Original Message----- From: Goodrichs [mailto:nbd95@macconnect.com] Sent: Saturday, December 04, 1999 8:13 PM To: zope@zope.org 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:chrism@digicool.com 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 - Zope@zope.org 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 )
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
Goodrichs wrote:
We don't count here until I'm sure I am explaining it correctly ;^)
Thank god. :-)
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?
Yes... One more time, with feeling. OK, this is an ugly, ugly hack. There is undoubtedly a better way to do this. It's also untested. <dtml-call "REQUEST.set('myvar', 'a.space.separated.string')"> <dtml-call "REQUEST.set('mylist', _.string.split(myvar,'.')"> <dtml-call "REQUEST.set('baseobjectstring', mylist[0])"> <dtml-call "REQUEST.set('baseobject', _.getitem(baseobject, 0)"> <dtml-call "REQUEST.set('myurl', baseobject.absolute_url())"> <dtml-in mylist> <dtml-if sequence-start> <dtml-else> <dtml-call "REQUEST.set('myurl', myurl+'/'+_['sequence-item']"> </dtml-if> </dtml-in> <IMG SRC="<dtml-var myurl>"> Get the idea? What I'm trying to do here is get away from objects and build a string using the URL path instead. First we build a list of (potential) object names using string.split from a dot-separated string and put it in mylist. Then we get a handle on the "base" object via getitem (it'll be first in the mylist list). Then we get that object's "absolute url". (This is gonna fail if there is no such object, you'll want to wrap it in a try). We go through the items in mylist in the in loop (skipping the first one by using if sequence-start, that's the base object). Then we cycle through the rest of the mylist list, appending a slash and the next object name. And so on until we get to the end of the list. The result should be, (assuming the "a" object has an absolute url of http://mysite.com/a): <IMG SRC="http://mysite.com/a/space/separated/string"> You could also probably replace the line that appends the sequence-item to myurl with an .append method, I'm too lazy. You wanna design your site around string representations of objects. Well, who am I to say no?!
oops.. replace: <dtml-call "REQUEST.set('baseobject', _.getitem(baseobject, 0)"> with: <dtml-call "REQUEST.set('baseobject', _.getitem(baseobjectstring, 0)">
You wanna design your site around string representations of objects. Well, who am I to say no?!
We are always open to other ideas! But consider this (from a website builders point of view and not a Zopeista's point of view). I have a website with 2000+ pages and 200+ folders. I want to have a header displayed with a unique set of graphics for each page based on the page name and the parent directory name. http://www.mysite.com/firstlevel/firstpage.html this page would display a graphic named "firstlevelFirstpage.gif" This makes perfect sense from an organizational standpoint, if I need to replace one of 1100 images I can find the image just by knowing the page it would be displayed on. Conversly I know which image every page requires by virtue of knowing the pages location within the website. What we are tying to do is write a method that can be sent a string constructed from the existing properties of a page (document_id and folder_id), then find and display the appropriate graphic. This way we can place a single line of common dtml in any page and display the proper graphic; <dtml-var myimageMethod(Document_id, Folder_id, "some_identifier")> Currently Zope is making it very difficult to do this because it will not accept a string representation of a Zope object. We have tried many different ways, all wrong, all due to our own lack of understanding the Zope namespace and python. Tools like this would make building large group maintained website much easier, reuseable code, templates, universal methods, all combined give you the ability to add/subtract/modify pages easily. Dealing with a large constantly changing website this is very important to us. We need to be able to give our artist a simple naming scheme for imagry and our designer a single tag to use for ALL images. It seems the code you sent will do this but I don't think you liked it ;^) . We also went down the same road last night thinking it may be the way to do what we wanted (converting the string to a url path and returning the image tag to the calling document) But, we are open to any suggestions to solve the problem. Thanks for all the help, we'll give your code a try. DAve.
participants (3)
-
Chris McDonough -
David Kankiewicz -
Goodrichs