I'm struggling with how to do this in Twig... I feel like it would be easier in a full programming language.
If an entry's categories look like this:
A - A1 - A2 B C - C1
I need to output a list like this:
A > A1 A > A2 B C > C1
I can't seem to figure out how to avoid printing all the top-level categories on their own. This is what I've managed to output:
A A > A1 A > A2 B C C > C1
I have a feeling I'm going to feel dumb when someone answers this, but any help is appreciated.
Edit: I've found a solution.
Before listing the categories, I run a
for loop on just the entry's level 2 categories and collect their parents' IDs using an empty array and the
merge filter. Then, when listing the categories, I put a conditional so that level 1 categories are not listed if their ID is in the array.
It seems an awkward way to do it, and I'm still interested in better solutions.