I am trying to write a snippet of code that will figure out what main directory you are in and display a different banner based on that. Should be simple as heck, well... it has been driving me crazy. Here is what I have and I know I am missing one stupid line of code or something. dtml-let section="_.string.split(_.string.lower(_.string.split(URL, '/')[3]), '.')"> <dtml-call "REQUEST.set('section', section)"> </dtml-let> <dtml-if section> <dtml-if "section=='folder_name'"> show new header <dtml-else> do something else </dtml-if> </dtml-if section> And this is the output and why it won't match which I think is because the first one is in a list. (??!) ['folder_name'] = folder_name Any help? BZ
On Thu, Dec 05, 2002 at 01:33:03PM -0500, BZ wrote:
dtml-let section="_.string.split(_.string.lower(_.string.split(URL, '/')[3]), '.')"> <dtml-call "REQUEST.set('section', section)"> </dtml-let>
<dtml-if section>
<dtml-if "section=='folder_name'">
show new header
And this is the output and why it won't match which I think is because the first one is in a list. (??!)
['folder_name'] = folder_name
The ridiculously naive solution (since section is a one-item list) would be to use <dtml-if "section==['folder_name']"> but that's a bit silly. A slight improvement would be <dtml-call "REQUEST.set('section', section[0])"> Any better options would require more Python/DTML Zen than I have currently. But I'd think about making a Python Script called whichsection, with code something like: request = container.REQUEST url=string.lower(request.URL) section=string.split(url,'/')[3] print section return printed and then test <dtml-if "whichsection=='folder_name'">. I probably missed a split on '.', but none of my URLs have periods in them anyway. It took me quite a while to get in the habit of replacing DTML logic with Python Scripts, but it's *lots* more readable due to the less excessive punctuation (I don't even write Python code that often, and experimented my way to the above code by reading and converting your DTML-Python). -- Mike Renfro / R&D Engineer, Center for Manufacturing Research, 931 372-3601 / Tennessee Technological University -- renfro@tntech.edu
Let's assume 'folder_name' is 'Sports'. Provided you've been careful of not using this name anywhere else in your site (that's what you usually must do when use folders as sections): <dtml-if Sports> I'm at Sports section <dtml-else> I'm at any other section </dtml-if> Ausum ----- Original Message ----- From: "BZ" <bz@bwanazulia.com> To: <zope@zope.org> Sent: Thursday, December 05, 2002 1:33 PM Subject: [Zope] Comparing directories & dumb question
I am trying to write a snippet of code that will figure out what main directory you are in and display a different banner based on that. Should be simple as heck, well... it has been driving me crazy. Here is what I have and I know I am missing one stupid line of code or something.
dtml-let section="_.string.split(_.string.lower(_.string.split(URL, '/')[3]), '.')"> <dtml-call "REQUEST.set('section', section)"> </dtml-let>
<dtml-if section>
<dtml-if "section=='folder_name'">
show new header
<dtml-else>
do something else
</dtml-if>
</dtml-if section>
And this is the output and why it won't match which I think is because the first one is in a list. (??!)
['folder_name'] = folder_name
Any help?
BZ
_______________________________________________ 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 )
participants (3)
-
Ausum Studio -
BZ -
Mike Renfro