流体 - 检查值是否为 NULL 的条件不起作用

Fluid - condition to check if value is NULL not working

我尝试仅在 属性 fileEn 的值为 NULL (fileEn => NULL)

时输出我的元素
<f:if condition="{file.fileEn}==NULL">
    <f:debug title='file'>{file}</f:debug>
</f:if>

然而,这也向我展示了 fileEn 不是 NULL!

的元素

你不能检查某物是否是这样的 NULL,它的工作原理是这样的:

仅当 属性 为 NULL 时渲染:

<f:if condition="{file.fileEn}">
    <f:then>

    </f:then>
    <f:else>
        <!-- Property is NULL -->
        <f:debug title='file'>{file}</f:debug>
    </f:else>
</f:if>

仅当 属性 为 NOT NULL 时渲染:

<f:if condition="{file.fileEn}">
    <!-- Property is not NULL -->
    <f:debug title='file'>{file}</f:debug>
</f:if>

或者您可以这样做:

<f:if condition="{file.fileEn}==">
    <f:debug title='file'>{file}</f:debug>
</f:if>
<f:if condition="{0:myVariable} == {0: NULL}'"></f:if>

应该也可以

不要使用 f:if ViewHelper 在 NULL 上进行测试:使用它,falsy 而不是 NULL 值将被错误地视为 NULL,例如当 file.fileEn = "0".

改为使用 IsNullViewHelper:

<html
  xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
  xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
  data-namespace-typo3-fluid="true"
>

  <v:condition.variable.isNull value="{file.fileEn}">
    <f:then>
      is NULL
    </f:then>
    <f:else>
      is not NULL
    </f:else>
  </v:condition.variable.isNull>

</html>