[英]TYPO3 inline fluid condition and typoscriptObjectPath
I search for a solution for inline fluid condition and typoscriptObjectPath. 我在寻找内联流体条件和typoscriptObjectPath的解决方案。
work fine: 工作正常:
<f:cObject typoscriptObjectPath="lib.currentDate" />
work fine: 工作正常:
<f:if condition="{price.day} == {f:cObject(typoscriptObjectPath:'lib.currentDate')}">
<f:then>work</f:then>
<f:else>dont work</f:else>
</f:if>
work fine: 工作正常:
{f:if(condition:'{price.day} == \'Sunday\'',then:'active',else:'test')}
DONT work 不要工作
{f:if(condition:'{price.day} == \'{f:cObject(typoscriptObjectPath:'lib.currentDate')}\'',then:'active',else:'test')}
how can i use the right inline code? 如何使用正确的内联代码?
You do not need to resolve lib.currentDate
cObject within your view, as you can just copy its output into fluid variable. 您无需在视图中解析
lib.currentDate
,因为您只需将其输出复制到Fluid变量即可。 It will avoid any problems with nested quotes, brackets etc. etc... Of course I assume, that's in combination with fluid template of the PAGE
: 它将避免嵌套引号,方括号等任何问题。当然,我认为这是与
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
}
}
}
so you can use it in condition just like: 因此您可以像下面这样使用:
<f:if condition="{price.day} == {currentDate}">That's today!</f:if>
<!-- or... -->
{f:if(condition:'{price.day} == {currentDate}', then: 'active', else: 'not-active')}
Of course if you're working in the plugin's context, you can do the same with assign
method within your action, like: 当然,如果您在插件的上下文中工作,则可以在操作中使用
assign
方法执行相同的操作,例如:
$this->view->assign('currentDate', strftime('%A',date('U')));
Note you have also other options: 请注意,您还有其他选择:
price.day
and currentDate
are different types and requires type conversion before comparison. price.day
和currentDate
为不同类型并且在比较之前需要类型转换时将很有用。 Create transient
field in your price
model, which' getter compares day field with strftime('%A',date('U'))
and return boolean
value, so you can use it directly as: 在
price
模型中创建一个transient
字段,getter将日期字段与strftime('%A',date('U'))
并返回boolean
值,因此您可以将其直接用作:
<f:if condition="{price.myTransientField}">Hooray!</f:if>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.