TYPO3 内联流体条件和 typoscriptObjectPath
TYPO3 inline fluid condition and typoscriptObjectPath
我正在寻找内联流体条件和 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,因为您只需将其输出 复制 到流体变量中即可。它将避免嵌套引号、括号等的任何问题......当然我假设,这是与 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')));
请注意,您还有其他选择:
- 创建自定义if ViewHelper,当
price.day
和currentDate
是不同的类型,比较时需要进行类型转换时会有用
在您的 price
模型中创建 transient
字段,getter 将日字段与 strftime('%A',date('U'))
和 return boolean
值,所以你可以直接使用它作为:
<f:if condition="{price.myTransientField}">Hooray!</f:if>
我正在寻找内联流体条件和 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,因为您只需将其输出 复制 到流体变量中即可。它将避免嵌套引号、括号等的任何问题......当然我假设,这是与 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')));
请注意,您还有其他选择:
- 创建自定义if ViewHelper,当
price.day
和currentDate
是不同的类型,比较时需要进行类型转换时会有用 在您的
price
模型中创建transient
字段,getter 将日字段与strftime('%A',date('U'))
和 returnboolean
值,所以你可以直接使用它作为:<f:if condition="{price.myTransientField}">Hooray!</f:if>