0

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!

1 Answer 1

0

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.

9
  • But the thing is, the exercises are attached to a given lesson. I think what you are suggesting would display the exercises that are in the same category as a lesson, but not necessarily in the lesson, you know what I mean? For instance, I have a category scales, and a lesson Major Scales and exercises in that lesson, but there is also a lesson Non-Major Scales, also in category Scales, but with different exercises. So exercises in both lessons are in category Scales, but the exercises are attached to specific lessons. Commented Oct 17, 2015 at 16:53
  • The same method applies to this situation - just add a "lesson" taxonomy reference to both content types and use that in your views instead of category. Commented Oct 17, 2015 at 17:56
  • Do you mean lesson entity reference? The only term reference is to category. Right now an exercise has a lesson reference, but a lesson does not have a lesson reference since that would just be the lesson node id. Commented Oct 17, 2015 at 18:03
  • You can use entity reference instead if that's what you prefer. Add a contextual filter for NID on both views. On the page view, provide a default value of Content ID from URL. On the attachment, add a relationship to your entity reference (the first one). Change the contextual filter to hide view when no argument is present. Commented Oct 17, 2015 at 18:35
  • Out of curiosity, how does the filter get the node id from the url if the url only has the term id? Thanks for the patience! Commented Oct 17, 2015 at 19:43

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.