bstrilziw
(Benjamin S)
March 27, 2020, 2:45pm
1
Hi there,
following situation: I want to create table of contents from all headlines on a page.
tocItems = Neos.Fusion:Loop {
items = ${q(node).find('[instanceof Neos.NodeTypes:Headline]').get()}
...
}
This will give me all headlines but not in the correct order. The ones that have the most parents (e.g. they are part of a row/column) come first, the ones on the first level last.
q(node).children
() gives me the ContentCollection ‘main’. Even if I can start at ‘main’, then I have the problem that the current item could be a headline or a ContentCollection with a headline in it. How do i solve this?
Thanks in advance
Benjamin
1 Like
mficzel
(Martin Ficzel)
March 28, 2020, 7:35am
2
The „find“ operation has no ordering as it searches all children of a node recursively and there is no efficient way to sort this hierarchy.
However the „children“ operation allows filtering aswell but only on the direct children and thus has a defined order.
${q(docomentNode). children(‘main ‘).children(’[instanceof Neos.NodeTypes:Headline]’).get()}
This query returns all headlines from the main collection of the current document. Does this help in your case?
bstrilziw
(Benjamin S)
March 28, 2020, 10:16am
3
Thank you, Martin! With your help I’ve got the solution:
tocItems = Neos.Fusion:Loop {
items = ${q(documentNode).children('main').children().get()}
itemRenderer = Neos.Fusion:Case {
isHeadline {
condition = ${q(item).is('[instanceof Neos.Neos:Headline]')}
renderer = Vendor.Package:TocItem {
item = ${item}
}
}
isContenCollection {
condition = ${q(item).is('[instanceof Neos.Neos:ContentCollection]')}
renderer = Neos.Fusion:Loop {
items = ${q(item).find('[instanceof Neos.Neos:Headline]').get()}
itemName = 'section'
itemRenderer = Vendor.Package:TocItem {
item = ${section}
}
}
}
}
}
Loop over all children. If it’s a Headline, render it. If it’s a ContentCollection, look for all Headlines and render them. Seems easy now…
sebobo
(Sebastian Helzle)
March 28, 2020, 3:52pm
4
Once upon a time I added a sorting operation to the listable package for a nested structure using the nodes relative index: https://github.com/Flowpack/Flowpack.Listable/blob/master/Classes/Fusion/Eel/FlowQueryOperations/SortRecursiveByIndexOperation.php
Maybe that can help you and you can either use the package or copy the helper.
1 Like