typo3neoscmstyposcript2

How to render content of parent documentNode in TYPO3 Neos?


I have a simple question. I have a custom content area on my page called "left". Its added to the NodeType "Page" as a childNode in the yaml file:

'TYPO3.Neos.NodeTypes:Page':
  properties:
    [...]
  childNodes:
    'left':
      type: 'TYPO3.Neos:ContentCollection'

In my TypoScript I added it to the page.body.content part:

page.body.content {
    main = PrimaryContent {
        nodePath = 'main'
    }
    left = ContentCollection {
        nodePath = 'left'
    }
}

I can add content to this new content area and it shows up in the frontend. Everything works just fine. Now I want to check if the ContentCollection of the current documentNode is empty and if this is the case I want to render the ContentCollection of the 'left' nodePath of the parent documentNode.

In other words: Subpages should render content of their parents if they dont have content on their own withing the defined content area.

How do I achieve this?


Solution

  • left = ContentCollection {
        @override.node = ${q(node).children('left').children().count() == 0 ? q(node).parent().get(0) : node}
        nodePath = 'left'
    }
    

    Is untested but should work just fine. Note that this only goes one level up. If you need to fallback to more levels this needs to be done a bit differently.