Fluid - condition to check if value is NULL not working
Asked Answered
C

5

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!

Cacilia answered 25/1, 2017 at 12:41 Comment(0)
C
11

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>
Cacilia answered 25/1, 2017 at 12:41 Comment(1)
This is not correct, in your case, the property could also be "" (empty string) or FALSE, besides NULL.Che
S
2
<f:if condition="{0:myVariable} == {0: NULL}'"></f:if>

Should also work

Stretchy answered 21/12, 2021 at 10:54 Comment(2)
I can't verify, I don't work with fluid anymore (thx god), but thx for your contribution.Cacilia
It works, but I am curious: why?Banausic
I
2

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>
Indelicacy answered 24/3, 2022 at 10:14 Comment(0)
G
0

Alternatively you can do this:

<f:if condition="{file.fileEn}==">
    <f:debug title='file'>{file}</f:debug>
</f:if>
Garcon answered 3/9, 2021 at 18:59 Comment(0)
P
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...

Polyclinic answered 28/6, 2023 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.