Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

[FEATURE] Allow comparison with null in `<f:if>` ViewHelper

Open simonschaufi opened this issue 2 years ago • 4 comments

It is not possible to use a condition with the <f:if /> ViewHelper to check directly against null value, like it is known from the PHP world.

For example, following php-code

  // strict comparison
  if ($variable === null) {}
  if ($variable !== null) {}

  // loose comparision
  if ($variable == null) {}
  if ($variable != null) {}

can now be written with fluid as

  <!-- /* strict comparison */ -->
  <f:if condition="{var} === null"></f:if>
  <f:if condition="{var} !== null"></f:if>

  <!-- /* loose comparison */ -->
  <f:if condition="{var} == null"></f:if>
  <f:if condition="{var} != null"></f:if>

which extinguish the need of a custom isNull ViewHelper in projects.

simonschaufi avatar Dec 19 '23 14:12 simonschaufi

In my opinion null should be added as general language construct and not parsed from string at occasional places.

I have no idea what exactly you mean by "general language construct". Can you given an example? Boolean things are parsed in the BooleanParser.

simonschaufi avatar Jan 23 '24 15:01 simonschaufi

There needs to be something like a TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NumericNode TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\TextNode but for null values.

=> TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\NullNode.

So that null is a language construct that is understood in all expressions, not just in boolean.

bnf avatar Jan 29 '24 15:01 bnf

@bnf I've started the implementation but now I'm stuck. I tried to copy what the NumericNode does but maybe I'm going the wrong way here. I also don't really understand what the BooleanNode does as it requires a comparison and not just "true" or "false". Can you help me please?

simonschaufi avatar Jan 29 '24 18:01 simonschaufi

Sorry, I can't provide further guidance without implementing it myself (which is currently not possible due to priorities).

bnf avatar Mar 18 '24 17:03 bnf

In my opinion null should be added as general language construct and not parsed from string at occasional places. Supporting it in conditions, but not contexts like parameters makes no sense from a developer experience and makes it hard to grasp what fluid actually supports.

Further discussion about this can happen in #911. I'm closing this PR, since we're taking a different approach.

s2b avatar Jul 20 '24 19:07 s2b