【问题标题】:TYPO3 inline fluid condition and typoscriptObjectPathTYPO3 在线流体条件和typoscriptObjectPath
【发布时间】:2016-02-28 10:06:30
【问题描述】:

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

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

【问题讨论】:

    标签: typo3 fluid


    【解决方案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. 创建自定义 if ViewHelper,这在 price.daycurrentDate 是不同类型并且需要在比较之前进行类型转换时很有用。
    2. price 模型中创建transient 字段,它的getter 将day 字段与strftime('%A',date('U')) 进行比较并返回boolean 值,因此您可以直接将其用作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-14
      相关资源
      最近更新 更多