Re: [Zope] Accesing a new context from a manipulated string
Here's my problem:
given a method itemURL(), that typically returns a site relative URL such as '/about/', I need to change to the appropriate directories context using <dtml-with>.
In short I need to do the equivalent of <dtml-with about>.
The closest I've gotten so far is:
<dtml-with expr="_.getitem(itemURL(), 0)">
which generates a KeyError: /about/ in the traceback.
Can anyone help me truncate the extra '/'s off of this string and pass it to the <dtml-with>?
This is going to be awkward in DTML, but it can be done. But there may be some different cases (all untested): simplest case '/about/' : <dtml-let strippedURL="itemURL()[1:-1]"> strippedURL -> 'about' more intricate case '/about/whatever/' <dtml-let strippedURL="itemURL()[1:-1]"> <dtml-let strippedURL="_.string.replace(strippedURL, '/', '.')"> strippedURL -> 'about.whatever' or, more convoluted <dtml-let strippedURL="_.string.replace(itemURL()[1:-1], '/', '.')"> if you're not certain if your itemURL has a starting and a trailing /, you will have to make this conditional. You're better off using a PythonMethod then. hth Rik
participants (1)
-
Rik Hoekstra