我在 drupal 7 中有一个学生书籍产品,他们有一个同伴教师的书籍产品。我想制作一个视图模式,显示学生书籍(产品展示)以及对教师书籍的实体引用,这也是书籍产品。问题是我可以显示 id、title 或呈现的实体,但不能显示其他实体字段。我要显示的是这样的:
学生的 ISDN: _ __ _ __
教师的 ISDN:_ __ _ __
... 其他产品领域(学生) ...
我已经尝试了几个模块,如显示套件,但没有,你能帮忙吗?我错过了什么?
我在 drupal 7 中有一个学生书籍产品,他们有一个同伴教师的书籍产品。我想制作一个视图模式,显示学生书籍(产品展示)以及对教师书籍的实体引用,这也是书籍产品。问题是我可以显示 id、title 或呈现的实体,但不能显示其他实体字段。我要显示的是这样的:
学生的 ISDN: _ __ _ __
教师的 ISDN:_ __ _ __
... 其他产品领域(学生) ...
我已经尝试了几个模块,如显示套件,但没有,你能帮忙吗?我错过了什么?
一个快速的解决方案是为您的内容类型创建一个新的节点模板。例如:node--student.tpl.php,然后使用以下代码作为示例:
$referenced_node = node_load($node->field_ref[LANGUAGE_NONE]['0']['target_id']);
print node_view($referenced_node, "teaser");
希望这可以帮助。
我是这样做的:
  // Initial weight
  $weight = 2;
  // Student's book entity
  $student_book_entity = $node->field_student_book[LANGUAGE_NONE][0]['entity'];
  // Get Student's book ISBN and alter some attributes
  $student_isbn_field = array_merge(field_view_field('commerce_product', $student_book_entity, 'field_book_isbn'), array(
      '#field_name' => 'field_students_book_isbn',
      '#title' => t('Student\'s Book ISBN'),
      '#weight' => $weight++,
    )
  );
  $node->content['field_students_book_isbn'] = $student_isbn_field;
  // Teacher's book entity
  $teachers_book_entity = $node->field_teacher_book[LANGUAGE_NONE][0]['entity'];
  // Get Teacher's book ISBN and alter some attributes
  $teacher_isbn_field = array_merge(field_view_field('commerce_product', $teachers_book_entity, 'field_book_isbn'), array(
      '#field_name' => 'field_teachers_book_isbn',
      '#title' => t('Teacher\'s Book ISBN'),
      '#weight' => $weight++,
    )
  );
  $node->content['field_teachers_book_isbn'] = $teacher_isbn_field;