I'm constantly running into this general problem in DTML - how do I access an object or property who's name is given in a string? Here's a specific problem: I've got a Zclass product that has a string property in a sheet that's supposed to hold the name of the prefered cascading style sheet used when rendering the object. The name is automatically added to the header of the html doc when rendered, like this: <link href="<dtml-var style_sheet>" ...> But the style sheet itself lives a few directories down from the document being rendered so I really want the absolute URL. If I could act the object I could do <dtml-var "css_object.absolute_url()"> - but the name css_object (or whatever) is the value of the string style_sheet. So how can I dereference the string? Thank, John
try something like: <untested> <dtml-var "_[style_sheet].absolute_url()"> </untested> Phil phil.harris@zope.co.uk ----- Original Message ----- From: "John Morton" <jwm@plain.co.nz> To: "zope" <zope@zope.org> Sent: Wednesday, May 10, 2000 9:34 AM Subject: [Zope] Soft References in DTML
I'm constantly running into this general problem in DTML - how do I access an object or property who's name is given in a string?
Here's a specific problem:
I've got a Zclass product that has a string property in a sheet that's supposed to hold the name of the prefered cascading style sheet used when rendering the object. The name is automatically added to the header of the html doc when rendered, like this:
<link href="<dtml-var style_sheet>" ...>
But the style sheet itself lives a few directories down from the document being rendered so I really want the absolute URL. If I could act the object I could do <dtml-var "css_object.absolute_url()"> - but the name css_object (or whatever) is the value of the string style_sheet.
So how can I dereference the string?
Thank, John
_______________________________________________ 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 )
object I could do <dtml-var "css_object.absolute_url()"> - but the name
This should do what you want, I used it to do something similar, but I haven't tested it: <dtml-var "_.getattr(PARENTS[-1].path.to.css.folder,css_object).absolute_url()"> Nice huh?! Someone please tell me a nicer way to do this... cheers, Chris
John Morton writes:
I'm constantly running into this general problem in DTML - how do I access an object or property who's name is given in a string?
Here's a specific problem:
I've got a Zclass product that has a string property in a sheet that's supposed to hold the name of the prefered cascading style sheet used when rendering the object. The name is automatically added to the header of the html doc when rendered, like this:
<link href="<dtml-var style_sheet>" ...>
But the style sheet itself lives a few directories down from the document being rendered so I really want the absolute URL. If I could act the object I could do <dtml-var "css_object.absolute_url()"> - but the name css_object (or whatever) is the value of the string style_sheet.
So how can I dereference the string?
<dtml-var "_[_['style_sheet']]"> All my best, Jason Spisak CIO HireTechs.com 6151 West Century Boulevard Suite 900 Los Angeles, CA 90045 P. 310.665.3444 F. 310.665.3544 Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
Jason Spisak wrote:
John Morton writes:
But the style sheet itself lives a few directories down from the document being rendered so I really want the absolute URL. If I could act the object I could do <dtml-var "css_object.absolute_url()"> - but the name css_object (or whatever) is the value of the string style_sheet.
So how can I dereference the string?
<dtml-var "_[_['style_sheet']]">
I don't think the above works, really. I would expect it to be written: <dtml-var "_[style_sheet]">, but this will render the stylesheet, not it's url, and (surprisingly) <dtml-var "_[style_sheet].absolute_url()"> will *not* work. The most consistent way to dereference a string is: <dtml-var "_.getitem(style_sheet).absolute_url()"> HTH, -- ethan mindlace fremen mindlace@imeme.net zope -&- imap email -&- mailing list weave your web with the web at http://imeme.net
mindlace writes:
Jason Spisak wrote:
John Morton writes:
But the style sheet itself lives a few directories down from the document being rendered so I really want the absolute URL. If I could act the object I could do <dtml-var "css_object.absolute_url()"> - but the name css_object (or whatever) is the value of the string style_sheet.
So how can I dereference the string?
<dtml-var "_[_['style_sheet']]">
I don't think the above works, really. I would expect it to be written:
<dtml-var "_[style_sheet]">, but this will render the stylesheet, not it's url,
Whoops. I thought you wanted the sheet's code at the top of the page. My fault.
and (surprisingly) <dtml-var "_[style_sheet].absolute_url()"> will *not* work.
The most consistent way to dereference a string is:
<dtml-var "_.getitem(style_sheet).absolute_url()">
That's it.
HTH, -- ethan mindlace fremen mindlace@imeme.net zope -&- imap email -&- mailing list weave your web with the web at http://imeme.net
_______________________________________________ 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 )
Jason Spisak CIO HireTechs.com 6151 West Century Boulevard Suite 900 Los Angeles, CA 90045 P. 310.665.3444 F. 310.665.3544 Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (5)
-
Chris Withers -
Jason Spisak -
John Morton -
mindlace -
Phil Harris