我在寻找内联流体条件和typoscriptObjectPath的解决方案。
工作正常:
<f:cObject typoscriptObjectPath="lib.currentDate" />
工作正常:
<f:if condition="{price.day} == {f:cObject(typoscriptObjectPath:'lib.currentDate')}">
<f:then>work</f:then>
<f:else>dont work</f:else>
</f:if>
工作正常:
{f:if(condition:'{price.day} == \'Sunday\'',then:'active',else:'test')}
不要工作
{f:if(condition:'{price.day} == \'{f:cObject(typoscriptObjectPath:'lib.currentDate')}\'',then:'active',else:'test')}
如何使用正确的内联代码?
您无需lib.currentDate
在视图中解析cObject,因为您只需将其输出复制到Fluid变量即可。它将避免嵌套引号,方括号等出现任何问题。当然,我认为这是与流体模板结合使用的PAGE
:
lib.currentDate = TEXT
lib.currentDate {
data = date:U
strftime = %A
}
page = PAGE
page {
# ....
10 = FLUIDTEMPLATE
10 {
# ....
variables {
mainContent < styles.content.get
currentDate < lib.currentDate
}
}
}
因此您可以在如下情况下使用它:
<f:if condition="{price.day} == {currentDate}">That's today!</f:if>
<!-- or... -->
{f:if(condition:'{price.day} == {currentDate}', then: 'active', else: 'not-active')}
当然,如果您在插件的上下文中工作,则可以对操作中的assign
方法执行相同的操作,例如:
$this->view->assign('currentDate', strftime('%A',date('U')));
请注意,您还有其他选择:
price.day
和currentDate
为不同类型时将很有用,并且在比较之前需要进行类型转换。transient
在price
模型中创建字段,getter将日字段与之比较strftime('%A',date('U'))
并返回boolean
值,因此您可以将其直接用作:
<f:if condition="{price.myTransientField}">Hooray!</f:if>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句