简体   繁体   中英

TYPO3 inline fluid condition and typoscriptObjectPath

I search for a solution for inline fluid condition and 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. 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 :

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:

$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.
  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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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