cili
cili

Reputation: 317

TypoScript: override COA if empty

I have 2 COAs: lib.productContent and lib.categoryContent which contain data from a user function. I also have a third COA - lib.seoColumns - which should contain by default the product COA. If the product COA is empty, it should be overridden by the category COA, but I don't know how to actually check if the product COA is empty:

########## PRODUCT CONTENT ##########
lib.productContent = COA
lib.productContent {
    10 = USER
    10 {
        userFunc = Vendor\Provider\UserFunc\Page->getPageContentByAlias
        alias = TEXT
        alias.data = GP:product
        aliasField.cObject = TEXT
        aliasField.cObject.value = product_alias
    }
}

########## CATEGORY CONTENT ##########
lib.categoryContent = COA
lib.categoryContent {
    10 = USER
    10 {
        userFunc = Vendor\Provider\UserFunc\Page->getPageContentByAlias
        alias = TEXT
        alias.data = GP:category
        aliasField.cObject = TEXT
        aliasField.cObject.value = category_alias
    }
}

########## SEO COLUMNS ##########
lib.seoColumns = COA
lib.seoColumns {
    10 < lib.productContent
    10.stdWrap.override.cObject < lib.categoryContent

    # 10.stdWrap.override.if    <-- IF WHAT ?

    wrap = <seoColumns><![CDATA[|]]></seoColumns>
}

Upvotes: 2

Views: 3383

Answers (2)

Wolffc
Wolffc

Reputation: 1250

Easiest way would be to use the stdWrap .ifEmpty function https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Stdwrap/Index.html#ifempty

lib.seoColumns = COA
lib.seoColumns {
   10. < lib.productContent
   10.stdWrap.ifEmpty.cObject < lib.categoryContent
   wrap = <seoColumns><![CDATA[|]]></seoColumns>
}

as ifEmpty is of type string/stdWrap it supports stdWrap Attributes and we can use .cObject to load another Content Object. like the COA for the second case.

Upvotes: 4

Jo Hasenau
Jo Hasenau

Reputation: 2684

Just do it the other way around, since override only will do the actual override, when there is at least something in the overriding object.

https://docs.typo3.org/typo3cms/TyposcriptReference/Functions/Stdwrap/Index.html#override

########## SEO COLUMNS ##########
lib.seoColumns = COA
lib.seoColumns {
  10 < lib.categoryContent
  10.stdWrap.override.cObject < lib.productContent
  wrap = <seoColumns><![CDATA[|]]></seoColumns>
}

no if necessary.

Upvotes: 2

Related Questions