문제

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.

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top