Home
The Toolkit for Online Communities
17125 Community Members, 0 members online, 2114 visitors today
Log In Register
OpenACS Home : Forums : OpenACS Development : New template tags - switch statement : One Message

Forum OpenACS Development: Re: New template tags - switch statement

Collapse
Posted by Lars Pind on
Dan,

This is beautiful, thanks.

I only have one suggestion, which would be to move the condition entirely into the <case> par, for improved readability of the templates, like this:

<switch>
  <case @foobar@ true>
    ...
  </case>
  <case @baz@ eq "greble">
    ...
  </case>
  ...
  <case default>
    ...
  </case>
</switch>

That would make it easier to read the template, because you don't have to read both the <switch> statement and the <case> statement to find out what's going on.

/Lars

Collapse
Posted by Jeff Davis on
Lars, shouldn't your construct be
<if @foobar@ true>
    ...
</if>
<elseif @baz@ eq "greble">
  ...
</elseif>
...
<else>
  ...
</else>
(and we probably should add an elseif tag).
Collapse
Posted by Dan Wickstrom on
Looking in tag-init.tcl, I see that an elseif tag already exists, but I'm not sure why nobody ever uses it.  I sorta of recall a discussion in the past where it was mentioned that there were some problems with elseif, but looking at they code I don't see anything wrong with it.... and giving it a short test, I find that it does indeed work.
Collapse
Posted by Jeff Davis on
It looks like this was in the original import but never got documented.  That will teach me to use the templating documentation to check which tags exist :)
Collapse
Posted by Malte Sussdorff on
This addition is great and makes templates considerably more readable for non programmers. Though I disagree with Lars concerning his idea for storing the variable as well in the case statement for the following reasons:
  • You have to mention the variable in every case statement. Despite the fact that this allows a switch for multi variable combinations it does add more code and you have to doublecheck every case statement whether the variable is the same as in the above case statement.
  • As a grafik designer I'd see the switch statement, see what variable it concerns and decide quickly whether I'd want to change the code in between. That wouldn't work otherwise.
  • One suggestion would be to have the default behaviour as it is defined right now and add a flag "multiple" to the switch statement with no variable following. This would say that the variables are contained within the case tags as suggested by Lars. We'd just have to encourage people (either by code or by documentation), not to use the multiple functionality if the flag is not set correctly, otherwise you really don't know what might be happening :).