Fusion itemRenderer @if.noChildElement

Hi guys,

how can I exclude an element to render if no child for the current element exists?
In this case, a list with all clients gets rendered. But if the ClientRenderer has no latestVideoPoster it should be excluded from the list.

My approaches with @if didn’t worked so hope someone can help me.

Thank you!

prototype(Vendor:ClientList) < prototype(TYPO3.TypoScript:Collection) {
          collection = ${q(site).find('[instanceof Vendor:Client][layout*="commercials"]').sort('title', 'ASC').get()}
          itemName = 'node'
          itemRenderer = Vendor:ClientRenderer
}
        
prototype(Vendor:ClientRenderer) < prototype(TYPO3.TypoScript:Template){
   templatePath = 'resource://Vendor/Private/Templates/NodeTypes/IsotopeCommercialElement.html'
   title = ${q(node).property('title')}
   category = ${q(node).property('category')}
   agent = ${q(node).property('agent')}
   additionalCategories = ${q(node).property('additionalCategories')}


   clientLink = TYPO3.Neos:NodeUri {
        node = ${q(node).get(0)}
   }

   latestVideoPoster = Vendor:VideoPoster {
        @context.node = ${q(node).children('[instanceof Vendor:Video]').sort('creationdatetime', 'DESC').get(0)}
     }
}

prototype(Vendor:VideoPoster) < prototype(TYPO3.TypoScript:Template) {
    templatePath = 'resource://Vendor/Private/Templates/NodeTypes/VideoPoster.html'
    title = ${q(node).property('title')}
   pictures = ${q(node).property('pictures')}
}

Hello Alex,

i see two direct approaches:

  1. Use TYPO3.TypoScript:Case as renderer in the collection to switch to another renderer or to skip items:

     prototype(Vendor:ClientList) < prototype(TYPO3.TypoScript:Collection) {
        ...
        itemRenderer = TYPO3.TypoScript:Case {
          hasVideo {
             condition = ${q(node).children('[instanceof Vendor:Video]').is()}
             renderer = Vendor:ClientRenderer
          }
          # no default is defined here
     }
    
  2. Add @if condition to renderers in the collection

     prototype(Vendor:ClientList) < prototype(TYPO3.TypoScript:Collection) {
        ...
        itemRenderer = Vendor:ClientRenderer
        itemRenderer.@if.hasVideo = ${q(node).children('[instanceof Vendor:Video]').is()}
     }
    

I am sure there are other ways aswell but those came to my mind first.

Hi Martin,

thank you very much!
I have chosen #2, but thank you for #1, too, as #1 is more flexible if I’d need more conditions.

I tried it before like you suggested it in #2, but now I see that my query was wrong…

Thx again,
Alex