简体   繁体   English

TYPO3内联流体状况和typoscriptObjectPath

[英]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: 请注意,您还有其他选择:

  1. Create custom if ViewHelper, which will be useful when price.day and currentDate are different types and requires type conversion before comparison. 如果ViewHelper创建自定义,则在price.daycurrentDate为不同类型并且在比较之前需要类型转换时将很有用。
  2. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM