4

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

Adrian Dymorz
  • 875
  • 8
  • 25
Renato Morell
  • 53
  • 1
  • 8

2 Answers2

6

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.

Bernd Wilke πφ
  • 10,390
  • 1
  • 19
  • 38
1

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\'
  )}'
)}
webman
  • 1,117
  • 15
  • 41
  • 1
    `your condition will default to 'Value is 2' although the value might not be` - I cannot see that. My example just shows nothing if the value is neither 1 or 2 (like expected) – Renato Morell Nov 09 '17 at 16:17
  • 1
    Ok, TYPO3 often is surprising to me, on my localhost I had this result but I intended to give some extra info, what about the inline anotation ? that did work on my localhost... I will correct my answer... – webman Nov 10 '17 at 05:18
  • 1
    Yes, the inline notation works like this! I hoped there is a way without nesting. – Renato Morell Nov 10 '17 at 07:51