简体   繁体   English

在 Drupal 8/9 中如何根据节点引用配置视图块?

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

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'. ENG 101:“文学”课程类型和“夏季”学期
  • MTH 101: course type of 'Math' and a semester of 'Fall'. MTH 101:“数学”课程类型和“秋季”学期

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!!任何帮助将不胜感激!!

  • Create a block view that displays courses (content type filter).创建一个显示课程的块视图(内容类型过滤器)。
  • Create 2 "contextual filters", 1 for course type and 1 for semester .创建 2 个“上下文过滤器”,1 个用于课程类型,1 个用于学期
  • In the above contextual filters, set them both to "When filter is not available" to "Provide default value" -> "Content ID from URL".在上面的上下文过滤器中,将它们都设置为“当过滤器不可用时”到“提供默认值”->“来自 URL 的内容 ID”。
  • 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在视图设置页面 (admin/structure/views/settings) 上有一个“显示 SQL 查询”的设置,这有助于在预览中查看 SQL 查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM