I have an attribute Link that contains the URL of an object (e.g. "/blah/foo"), and I want to do something like <dtml-with Link> .... </dtml-with> which of course doesn't work. How to I convert a URL into a reference to an object? -- Itamar - itamars@ibm.net ---------------------------o----------------------------------------------o Perl/Gimp Greeting Cards | Trust? Ha! The US dollar is backed by ICBMs! | http://www.sealingwax.com | --Anonymous Coward, Slashdot |
On Sun, Oct 31, 1999 at 08:43:50PM +0200, Itamar Shtull-Trauring wrote:
I have an attribute Link that contains the URL of an object (e.g. "/blah/foo"), and I want to do something like <dtml-with Link> .... </dtml-with>
which of course doesn't work.
How to I convert a URL into a reference to an object?
Maybe dereferencing the name? <dtml-with "_[Link]"> ... </dtml-with>
-- Itamar - itamars@ibm.net ---------------------------o----------------------------------------------o Perl/Gimp Greeting Cards | Trust? Ha! The US dollar is backed by ICBMs! | http://www.sealingwax.com | --Anonymous Coward, Slashdot |
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(Related lists - please, no cross posts or HTML encoding!
To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce
For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
-- Linux. The Choice of a GNU Generation! -> http://www.debian.org
Rafael Cordones Marcos wrote:
I have an attribute Link that contains the URL of an object How to I convert a URL into a reference to an object?
Maybe dereferencing the name?
<dtml-with "_[Link]"> ... </dtml-with>
Nope - that doesn't work.
Hi Itamar, Well I have done this with an external method. Something on the lines of (untested in this form) def urlToobject(self, url=None): string.replace(url,'/','.') return eval(url) You migh need a bit more than that depending on whether you need to get it from the root or from a specific dir etc. But something on these lines should work. HTH Phil phil@WigWamWeb.net -----Original Message----- From: itamar@localhost.localdomain [mailto:itamar@localhost.localdomain]On Behalf Of Itamar Shtull-Trauring Sent: Monday, November 01, 1999 8:35 AM To: Rafael Cordones Marcos Cc: zope@zope.org Subject: Re: [Zope] Convert URL to object Rafael Cordones Marcos wrote:
I have an attribute Link that contains the URL of an object How to I convert a URL into a reference to an object?
Maybe dereferencing the name?
<dtml-with "_[Link]"> ... </dtml-with>
Nope - that doesn't work. _______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope (Related lists - please, no cross posts or HTML encoding! To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
Phil Harris wrote:
Well I have done this with an external method.
Okay, I have an external method: def urlToobject(url=None): from string import replace replace(url,'/','.') return eval(url) I get a Error Type: NameError Error Value: QuickStart when I give QuickStart as the url (urlToobject('QuickStart')) where my dtml method is at the top level. And QuickStart does exist, of course.
OK try this, def urlToObject(self,url=None): from string import replace url=replace(url,'/','.') return eval("self.%s()" %url) which should be called by something like this: <dtml-var "urlToObject(url='tt_xml/index_html')"> However, this doesn't seem to work quite as you might expect. There must be a better way. Hmmm Phil phil@WigWamWeb.net -----Original Message----- From: itamar@localhost.localdomain [mailto:itamar@localhost.localdomain]On Behalf Of Itamar Shtull-Trauring Sent: Monday, November 01, 1999 10:17 AM Cc: zope@zope.org Subject: Re: [Zope] Convert URL to object Phil Harris wrote:
Well I have done this with an external method.
Okay, I have an external method: def urlToobject(url=None): from string import replace replace(url,'/','.') return eval(url) I get a Error Type: NameError Error Value: QuickStart when I give QuickStart as the url (urlToobject('QuickStart')) where my dtml method is at the top level. And QuickStart does exist, of course. _______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope (Related lists - please, no cross posts or HTML encoding! To receive general Zope announcements, see: http://www.zope.org/mailman/listinfo/zope-announce For developer-specific issues, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
To turn a path into an object, try-- <dtml-var "REQUEST.resolve_url(path)"> Note that path must be the fully qualified URL of the object. If you only have an absolute path (for example, '/Members/MikeP/some_object') use this: <dtml-var "REQUEST.resolve_url(SCRIPT_NAME + path)"> Mike.
Phil Harris wrote:
Hi Itamar,
Well I have done this with an external method.
Something on the lines of (untested in this form)
def urlToobject(self, url=None): string.replace(url,'/','.') return eval(url)
There is an existing method that works better for this: <dtml-with "REQUEST.resolve_url(Link)"> blah </dtml-with> 'Link' must be well formed, I believe it must be an absolute URL, but I'm not sure. Maybe just a path '/x/y' will work. -Michel
participants (5)
-
Itamar Shtull-Trauring -
Michel Pelletier -
Mike Pelletier -
Phil Harris -
Rafael Cordones Marcos