我对Fluid不太熟悉,我希望在Fluid中制作以下PHP语句。
if ($var == 'something') {
// do something
} elseif ($other-var == 'something else') {
// do something else
} else {
// do then the other thin
}
我该如何在Fluid中实现这个功能?文档中似乎没有elseif语句的说明。
自版本8起,TYPO3使用独立版本的Fluid模板引擎,该引擎经过大量开发并获得了许多新功能,例如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>
此外,还支持像这样的语法:
<f:if condition="{something} || {someOtherThing}">
Something or someOtherThing
</f:if>
使用Plain Fluid,您可以嵌套两个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>
或者你可以实现自己的ViewHelper,或者使用一个像VHS这样的ViewHelper库,它具有更优雅的ViewHelper来实现这个功能。
在 Typo3 7 LTS 中存在 AND 和 OR 的可能性:
http://typo3blogger.de/fluid-ifviewhelper-conditions-verknupfen/
AND:
<f:if condition="{0: value1, 1: value2} == {0: myValue1, 2: myValue2}">
<!-- your code-->
</f:if>
或者(在检查至少一个变量不为空的示例中):
<f:if condition="{0: value1, 1: value2} != {0: 0, 2: 0}">
<!-- your code-->
</f:if>
有没有关于“else if”的内联符号? 这个不起作用:
{f:if(condition: '{value} == 1', then: 'Value is 1', else if: '{value} == 2', then:'Value is 2')}
{f:if(condition: '{condition}', then: 'true', else: 'false')}
- Meek