[Zope] Switch, Attribution and NT

R. David Murray bitz@bitdance.com
Tue, 23 May 2000 14:12:03 -0400 (EDT)


On Tue, 23 May 2000, peter wrote:
> Q1 {A} --------------------------------------------------------
> Is it possible to rewrite the following piece of DTML into something easier
> and managable?
> <dtml-if "_.string.split(URL,'/')[-1]=='foobar_html'">
> 	Cool! You are viewing foobar_html
> <dtml-elif "_.string.split(URL,'/')[-1]=='barfoo_html'">
> 	More cool! You are viewing barfoo_html
> <dtml-elif ...
> <dtml-elif ...
> </dtml-if>
> 
> This is supposed to be in the standard_html_header, and I now wonder if it
> is possible to write an switch or case statement for this.

Well (untested),

<dtml-let greetings="{'foobar_html': 'Cool! You are viewing foobar_html',
  'barfoo_html': 'More cool! You are viewing barfoo_html'}">
<dtml-var "greetings[_.string.split(URL,'/')[-1]]">
</dtml-let>

might get you somewhere useful, depending on what it is you really
want to do.  (You might want 'dtml-try' code in case the last path
element isn't in your array.)

There isn't any dtml-case type statement.

> Q1 {B} --------------------------------------------------------
> How do you write an AND and OR in an IF-statement?
> I have tried this:
> <dtml-if "_.string.split(URL,'/')[-2]=='pornfolder' OR/AND
> _.string.split(URL,'/')[-2]=='murder_todolist_folder'">
> 	You are viewing the pornfolder AND/OR the murder_todolist_folder!!
> </dtml-if>
> ...but that does not work.

What fails about it?  I presume your 'AND/OR' means you have tried
both keywords and had similar failures.  The syntax is right
as far as I can see, though of course the AND case could never
evaluate to true in this specific example.

> I would also like to use something like this:
> "...=='pornfolder' OR/AND 'murder_todolist_folder'"

The way to write this in python would be (untested):

<dtml-if "_.string.split(URL,'/')[-2] in ('pornfolder','murder_todolist_folder')">

An AND case of this would be nonsensical.

Your remaining questions I will leave to others.

--RDM