case statement in chameleon zpt

47 views
Skip to first unread message

george hu

unread,
Jul 12, 2012, 4:48:52 AM7/12/12
to pylons-...@googlegroups.com
Hi, I'm wondering how can I write a switch/case block like bellow:

<tal:block tal:switch="x">
   <tal:case="0 or 1"> 
      <div> ..... </div>
   <tal:case="2">
      <div> ....</div>
</tal:block>


it seems that  case doesn't support logic operator (and /or /not)here. So, is there any way I can do it in the switch?


Thanks

George Hu





Wade Leftwich

unread,
Jul 12, 2012, 5:15:38 PM7/12/12
to pylons-...@googlegroups.com
(0 or 1) evaluates to 1, so if x == 0 you won't get a hit.

If you must use switch here I think you're going to have to repeat yourself:

<div tal:switch='x'>
  <p tal:case='0'>zero or one</p>
  <p tal:case='1'>zero or one</p>
  <p tal:case='2'>two</p>
</div>

Or you could use tal:condition --

<div>
  <p tal:condition='x in (0,1)'>zero or one</p>
  <p tal:condition='x == 2'>two</p>
</div>


-- Wade

george hu

unread,
Jul 12, 2012, 10:38:30 PM7/12/12
to pylons-...@googlegroups.com
Can I use x in (0,1) in tal:condition, coz I think the switch is more concise here.

George Hu

--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pylons-discuss/-/6m7IqzAd304J.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.

Reply all
Reply to author
Forward
0 new messages