TYPO3内联流体状况和typoscriptObjectPath

塞巴斯蒂安·施马尔(Sebastian Schmal)

我在寻找内联流体条件和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')));

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

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

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章