源氏:如果/否则

发布于 2024-09-30 20:33:57 字数 513 浏览 0 评论 0原文

如何在 Genshi 模板语言中执行简单的 if/else?

我发现这张票,这似乎表明Genshi不支持if/else,但它并没有真正解释它支持什么。

我基本上只是想要这样的东西:

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

但我得到“错误指令:其他”。我应该使用 py:choose 吗?我真的不知道如何将它用于 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

っ左 2024-10-07 20:33:57

目前,你不能在 Genshi 中使用 if do else 构造,并且据我所知,没有计划添加它。相反,就像您提到的那样,使用 py:choose。以下是如何使用 py:choose 作为 if/else 构造的类型:

<py:choose ...>
  <py:when test="...">
    ${c.row.currency.upper()}
  </py:when>
  <py:otherwise>
   ${c.row.currency.upper()}
  </py:otherwise>
</py:choose>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文