How do you configure views block based on node reference in Drupal 8/9?

289 Views Asked by At

There is a node pages that holds reference fields of the taxonomies (course type and semester). For example:

  • Summer Literature Courses: course type of 'Literature' and a semester of 'Summer'.

There is a node courses that holds reference fields of the taxonomies. For example:

  • ENG 101: course type of 'Literature' and a semester of 'Summer'.
  • MTH 101: course type of 'Math' and a semester of 'Fall'.

I need to somehow get those courses on the page that both reference the same course type and semester

I figured I could create a views block and place that on all pages that have course type and semester defined. But I can't figure out how to configure the View to correctly filter the courses. Any help would be greatly appreciated!!

1

There are 1 best solutions below

0
On
  • Create a block view that displays courses (content type filter).
  • Create 2 "contextual filters", 1 for course type and 1 for semester.
  • In the above contextual filters, set them both to "When filter is not available" to "Provide default value" -> "Content ID from URL".
  • add the block to the page.

Both the "page" and "course" content type must be using the same fields for referencing the course type and semester.

On the view settings page (admin/structure/views/settings) there is a setting for "Show the SQL query" which is helpful to see the SQL query on the preview