【问题标题】:How to use "or" in freemarker templates如何在 freemarker 模板中使用“或”
【发布时间】:2015-05-12 16:19:50
【问题描述】:

我正在尝试根据数据的存在或缺乏来更改数据表的布局。我想写但不起作用的是:

<#if record.enduseraccount?has_content OR record.installedataccount?has_content>
  Table 1
<#else>
  table 2
</#if>

我不需要两个陈述都是正确的,只需要一个或另一个。我真的不想通过为每个变量添加一个新表来为我的模板添加大量长度。

【问题讨论】:

    标签: freemarker


    【解决方案1】:

    使用||

    请看documentation

    您也可以使用double question mark ?? 来检查该值是否缺失

    <#if record.enduseraccount?? || record.installedataccount??> ....
    

    【讨论】:

    • 谢谢!你相信我在上个月至少每周两次搜索我的问题的答案吗...
    猜你喜欢
    • 2012-06-14
    • 1970-01-01
    • 2012-06-04
    • 2021-10-11
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多