Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluid: if - then - elseif - else

Tags:

typo3

fluid

I'm a bit new to fluid and I want to make a the following php statement in Fluid.

if ($var == 'something') {
   // do something
} elseif ($other-var == 'something else') {
   // do something else
} else {
   // do then the other thin
}

How can I make this in Fluid? I don't see the elseif statement in the documentation.

like image 273
Tom Avatar asked Apr 05 '15 19:04

Tom


1 Answers

Since TYPO3 8LTS

Since version 8 TYPO3 uses the standalone version of fluid, that was heavily developed and got tons of new features like elseif:

<f:if condition="{var} == 'something'">
    <f:then>do something</f:then>
    <f:else if="{other-var} == 'something else'">do something else</f:else>
    <f:else>do the other thing</f:else>
</f:if>

In addition there is support for syntax like this:

<f:if condition="{something} || {someOtherThing}">
    Something or someOtherThing
</f:if>

Until and including TYPO3 7LTS

With Plain Fluid you can nest two if ViewHelper:

<f:if condition="{var} == 'something'">
    <f:then>
       // do something
    </f:then>
    <f:else>
        <f:if condition="{other-var} == 'something else'">
            <f:then>
                // do something else
            </f:then>
           <f:else>
               // do then the other thing
           </f:else>
        </f:if>
    </f:else>
</f:if>

Or you could implement your own ViewHelper or use a ViewHelper Library like VHS that have a ViewHelper that does this more elegant.

like image 163
Daniel Avatar answered Oct 15 '22 18:10

Daniel