Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Genshi: if/else

How do I do a simple if/else in the Genshi templating language?

I've found this ticket, which seems to suggest that Genshi doesn't support if/else, but it doesn't really explain what it supports instead.

I basically just want something like this:

  <py:if test="c.row.currency">
  ${c.row.currency.upper()}
  <py:else>
  ${c.row.dataset_.currency.upper()} 
  </py:if>

But I get 'Bad Directive: else'. Should I be using py:choose instead? I can't really get my head around how to use it for an if/else condition.

like image 510
AP257 Avatar asked Nov 08 '10 20:11

AP257


1 Answers

Currently, you can not if do else constructs in Genshi, and as far as I'm aware, there are no plans to add it. Instead, like you mentioned, use py:choose. The following is how you use py:choose as a type of if/else construct:

<py:choose ...>
  <py:when test="...">
    ${c.row.currency.upper()}
  </py:when>
  <py:otherwise>
   ${c.row.currency.upper()}
  </py:otherwise>
</py:choose>
like image 112
Alex Avatar answered Nov 07 '22 08:11

Alex