5

I try to output my element only if the value of the property fileEn is NULL (fileEn => NULL)

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

However this is also showing me elements where fileEn is not NULL!

Black
  • 18,150
  • 39
  • 158
  • 271

5 Answers5

10

You can't check if something is NULL like this, it works like this:

Render only if property is 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>

Render only if property is NOT NULL:

<f:if condition="{file.fileEn}">
    <!-- Property is not NULL -->
    <f:debug title='file'>{file}</f:debug>
</f:if>
Black
  • 18,150
  • 39
  • 158
  • 271
  • This is not correct, in your case, the property could also be "" (empty string) or FALSE, besides NULL. – Sven Oct 31 '22 at 15:23
1
<f:if condition="{0:myVariable} == {0: NULL}'"></f:if>

Should also work

Black
  • 18,150
  • 39
  • 158
  • 271
1

Don't use the f:if ViewHelper to test on NULL: using it, a falsy but not NULL value would incorrectly be considered NULL, e.g. when file.fileEn = "0".

Instead use the 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>
Abdull
  • 26,371
  • 26
  • 130
  • 172
0

Alternatively you can do this:

<f:if condition="{file.fileEn}==">
    <f:debug title='file'>{file}</f:debug>
</f:if>
Andreas B
  • 377
  • 3
  • 10
0
<v:condition.variable.isNull value="{newsItem.starttime}">

If I put something like this, the isNullViewHelper interprets this as a string, rather than as a variable...