At 13:36 01/11/99 , Jeff Rush wrote:
On Fri, 29 Oct 1999 20:01:15 +0200, Martijn Pieters wrote:
At 19:19 29-10-99 , Jeff Rush wrote:
Alright, what's the trick to be able to retrieve the URL of a Zope object via DTML whose id has blanks or punctuation in it? For example, in a normally-named object called 'site_css', I'd do:
Ex. 1 <LINK REL=stylesheet HREF=<dtml-var "site_css.absolute_url()"> TYPE="text/css">
<LINK REL=stylesheet HREF="<dtml-var "_.getitem('site.css', 0).absolute_url()">" TYPE="text/css">
This retrieves the object from the namespace without calling it.
Thanks Martijn -- that works fine! At the risk of sounding dumb, I don't quite understand it -- why does the 0th array element within object 'site.css' contain a pointer to the object itself and how would a Zope developer know this? I've been thru the Zope source and haven't come upon that particular construct.
And naturally, what resides at other offsets? Oleg Broytmann wrote that doing the say with offset 1 would result in a call to the object ???
The 0 is not an array index, but a flag. getitem is an alias for the __getitem__ method of the namespace object, and it has a few extra arguments, like this flag. It defaults to 1, which means that the namespace will return the result of a call to the object if it is callable, instead of the object itself. This is the same behaviour as when you name the object in the name attribute of the var tag, for example. The namespace object is implemented in C (cDocumentTemplate), but there is also a python version with every Zope install: lib/python/DocumentTemplate/pDocumentTemplate.py. Look at the TemplateDict class. -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------