Custom ContentCollection / Inherited Sidebar

Hi there,

does someone can give me a blueprint / example for creating a custom ContentCollection which I can fill with some query content?

What I need in short: How can I create a ContentCollection with custom content which is not bound to a nodePath, can hold every kind of content node and is simply rendered by “{content.sidebar2 → f:format.raw()}”?


Longer explanation for what I’m searching for:

The main goal is to create an inherited sidebar which should shown the contents of the parent pages.

I found a few links here (although they are quite old):

It seems not to be very difficult. Use a ContentCollection and fill it with content via query. Both links are showing a few examples for different cases. But maybe they are to old?

Something like this does not work:

sidebar2 = Neos.Neos:ContentCollection {
      nodePath = 'sidebar'
      collection = ${q(site).children('sidebar').children().get()}
}

Whatever I’m trying to put into the “collection” - it’s simply ignored. I always got a copy of the given sidebar of the current node (because the nodePath “sidebar” is rendered again).

What I’m missing?

I’m using NEOS 5.3.

Kind regards,

Maximilian

Ok, seems that I get it by myself. Using this with some changes from the NEOS demo page works for me:

1 Like

Hi Max,

yes the nodePath has to be correct or you don’t set it.
If you set it you shouldn’t need to set the collection.

Hi @sebobo

Thanks for reply. Maybe you can clearify the whole thing finally for me? Going on from this link here. It’s your article, right? https://mind-the-seb.de/de/blog/vermeidung-von-tiefer-verschachtelung-von-inhalten-in-neos-cms

There I can see ContentCollections without a nodePath, using @context.

Additional you say “has to be correct or you don’t set it”. This is what I assumed, that I can omit the nodePath to have the full control whatever I want to do with a ContentCollection. But if I do, I got the error:

No content collection of type Neos.Neos:ContentCollection could be found in the current node (/sites/my-site/node-wwr6eqq34u00d/node-bg9pwyvhxcvuy) or at the path "to-be-set-by-user". You might want to adjust your node type configuration and create the missing child node through the...

Means:

This is working for me, without the collection part. I got the content of the nodePath of the “Homepage”:

prototype(Neos.Demo:Document.Fragment.Content.Sidebar) < prototype(Neos.Fusion:Component) {
    renderer = Neos.Neos:ContentCollection {
        nodePath = ${q(site).children('sidebar').property('_path')}
    }
}

But this not (without the NodePath). I got the error above:

prototype(Neos.Demo:Document.Fragment.Content.Sidebar) < prototype(Neos.Fusion:Component) {
    renderer = Neos.Neos:ContentCollection {
        collection = ${q(site).children('sidebar').children()}
    }
}

Ah sorry.

collection belongs to the internal ContentCollectionRenderer.

So you either

  • define the nodePath
  • or content.collection (not recommended)
  • set the desired node as @context.node = ${mySidebarCollectionNode}

The later works as the fallback for the content collection is to read the children from the current node in the context.

1 Like