流体:if - then - elseif - else

Tom*_*Tom 4 typo3 fluid

我对流体有点新意,我想在Fluid中制作以下php语句.

if ($var == 'something') {
   // do something
} elseif ($other-var == 'something else') {
   // do something else
} else {
   // do then the other thin
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在流体中做到这一点?我没有在文档中看到elseif语句.

Dan*_*iel 16

自TYPO3起8LTS

从版本8开始,TYPO3使用独立版本的流体,这是一个大量开发并获得了大量新功能,如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>
Run Code Online (Sandbox Code Playgroud)

另外还支持这样的语法:

<f:if condition="{something} || {someOtherThing}">
    Something or someOtherThing
</f:if>
Run Code Online (Sandbox Code Playgroud)

直到并包括TYPO3 7LTS

使用Plain Fluid,如果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>
Run Code Online (Sandbox Code Playgroud)

或者您可以实现自己的ViewHelper或使用像VHS这样的ViewHelper库,它具有更优雅的ViewHelper.