Freemarker - 检查布尔值

Freemarker - Check Boolean value

检查 FreeMarker 中表单数据的布尔值是否正确的语法是什么,我的代码:

<#if "${form.allStores}" !false>
        <@displayRow label="Receiving Stores" value="All Stores" />
    <#elseif "${form.storesReceiving}" == false || "${form.storesReceiving}"?has_content>
        <@displayRow label="Receiving Stores" value="No Stores"/>
    <#else>

我收到这个错误:

Could not prepare mail; nested exception is freemarker.core._MiscTemplateException: Can't convert boolean to string automatically, because the "boolean_format" setting was "true,false", which is the legacy default computer-language format, and hence isn't accepted. --

Freemarker 自版本 2.3.23 以来有 then function

<@displayRow label="Receiving Stores" value="${form.allStores?then('All Stores', 'No Stores')}"/>

Used like booleanExp?then(whenTrue, whenFalse)

也类似于java,可以用! operator取反:

<#if !form.allStores> 
    <@displayRow label="Receiving Stores" value="No Stores"/>

那么布尔值只能是 true/false 所以不需要 elseif :

<#else>
    <@displayRow label="Receiving Stores" value="All Stores" />
</#if>

Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.

也更喜欢使用第一个肯定条件作为:

<#if form.allStores> 
    <@displayRow label="Receiving Stores" value="All Stores" />
<#else>
    <@displayRow label="Receiving Stores" value="No Stores"/>
</#if>