TYPO3内联流体条件和typoscriptObjectPath

时间:2016-02-28 10:06:30

标签: typo3 fluid

我搜索内联流体条件和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')}

我如何使用正确的内联代码?

1 个答案:

答案 0 :(得分:1)

您无需在视图中解析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')));

请注意,您还有其他选择:

  1. 如果是ViewHelper,则创建自定义,这在price.daycurrentDate是不同类型时非常有用,并且在比较之前需要进行类型转换。
  2. transient模型中创建price字段,其中'getter将日期字段与strftime('%A',date('U'))进行比较并返回boolean值,以便您可以直接将其用作:

    <f:if condition="{price.myTransientField}">Hooray!</f:if>
    
相关问题