i need to create a collapsible menu tree from taxonomy terms and nodes which belong to them (not nested terms, but content pages) i'm totally stuck about it i've found solutions for nested taxonomy terms only, but not for combined with content pages from the term. meaning menu tree like this:

enter image description here

3 Answers 3


It's very simple to create the tree structure output you're looking for:

  1. Create the Content type Views,
  2. add the Taxonomy term Field next to the Title field,
  3. under Format Views settings choose to group by the Taxonomy field Grouping field Nr.1

On the Taxonomy field choose Exclude from display.

This will give you a list of nodes that are displayed in groups by their taxonomy terms.

To make that structure collapsible you can use some special option for the Format, for example Views Accordion or Views tree.


That's probably an opinion-based thing and actually also a too broad question. But here's what I'd do:

  1. Programmatically create a new block.
  2. Provide a hook_theme and your own template to later render the output the way you want.
  3. Follow one answer from How to get all node entities tagged with a specific term? to get the data you need.
  4. In the block's build() function pass the data to your custom template and build the markup you need.
  5. Optional: Improve performance by either storing the data from step 3. in some Drupal variable that can be purged from some admin settings form button click. Or add some custom cache tags that get invalidated as soon as taxonomy or node CRUD operations take place.

You probably can achieve what you want with some Views voodoo, and maybe should try that first, depending on your programming skills.

  • i've tried a lot of views voodoo but i'm afraid i have too poor programming skills, do you know any other way to do that? Jun 13, 2019 at 10:21
  • @thunderstorm – That's a chance to learn something that will definitely boost your career. Start with a custom block from a custom module, let it print "Hello World" and then continue, step by step.
    – leymannx
    Jun 13, 2019 at 10:48

I have a view set up that sounds similar to what I think you are trying to accomplish:

  1. Create your content view filtering by taxonomy.
  2. Create your taxonomy view.
  3. Go back to your content view and use "no results behavior" under "advanced" and insert your taxonomy view into your content view as a "global view area".

Now where there is no content assigned directly to the parent term, your term view appears displaying child terms. You are basically using parent terms and % arguments in your path to set the depth of the "tree".

You will also have to set your child "term page display" under "manage display" to show the content view. It's pretty complicated but VERY functional! I hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.