TransWikia.com

How to use Views Page + Attachment to show parent and children nodes?

Drupal Answers Asked by Brian Huether on October 26, 2021

I have a site with a node type Lesson, which has a Category field that points to a taxonomy term.

There is another node type Exercise which is a child to a Lesson node.

I previously figured out how to make one view page for a term url that displays both a parent and child nodes. But I was thinking that maybe it is better to have a page view with an attachment, where the page would display a Lesson node’s fields and an attachment would display the children Exercise node’s fields.

The page view has relationship set to taxonomy term and contextual filter set to the category. Then it is set to display Lesson fields.

In the attachment view, parent is set to page, relationship is set to a Lesson reference field. But I have no idea what to choose as contextual filter because there is no filter for me to choose that will get me the lesson id. The attachment doesn’t seem to have a way to get the parent node id (lesson id) from a contextual filter, since the url will only have the term id.

Any ideas on how to make the attachment display the children of the parent that is displayed in the page view?

Thanks!

One Answer

It sounds like you're getting stuck messing with relationships in the view - this shouldn't be needed to do what you're trying to do. You can accomplish this with these basic settings:

Lesson: All your lesson fields + term reference to category

Exercise: All your exercise fields + term reference to category

Your view's page display just needs to be set up to display content of type lesson.

The part that I think you're missing is setting the contextual filter.

  1. Add the contextual filter Content: Has taxonomy term ID
  2. Provide default value -> Taxonomy Term ID from URL

Your attachment should be set to show the exercise content type. Add the same contextual filter to this display and make sure you have inherit contextual filters checked.

This will give you a page that displays the lesson, followed by all exercises tagged with the matching category.

Answered by Patrick Ryan on October 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP