Value is 1 Value is 2 Value is 1 Value is 2 Value is 1 Value is 2

Typo3 Fluid: elseif inline notation

5.2k Views Asked by At

Is there an inline notation for the following example?

<f:if condition="{value}==1">
    <f:then>Value is 1</f:then>
    <f:else if="{value}==2">Value is 2</f:else>
</f:if>

Thanks for your help

2

There are 2 best solutions below

1
Bernd Wilke πφ On BEST ANSWER

probably it will be the cascading of if-viewhelpers:

{f:if(condition:'{value}==1', 
    then:'Value is 1', 
    else:'{f:if(condition:\'{value}=2\', then:\'Value is 2\')}'
)}

with the usual drawback of escaping string-delimiter for stacked inline viewhelpers.

3
webman On

your condition will default to 'Value is 2' although the value might not be ... this is not true, anyhow a bit more complete:

<f:if condition="{value}==1">
  <f:then>Value is 1</f:then>
  <f:else if="{value}==2">Value is 2</f:else>
  <f:else>Value is not valid</f:else>
</f:if>

simple inline annotation that does not output anything if the two conditions are not met:

{f:if(condition:'{value}==1',
  then: 'Value is 1',
  else: '{f:if(condition:\'{value}==2\',then: \'Value is 2\')}'
)}

add the else clause in the second condition:

{f:if(condition:'{value}==1',
  then: 'Value is 1',
  else: '{f:if(condition:\'{value}==2\',
    then: \'Value is 2\',
    else: \'Value is not valid\'
  )}'
)}