1
我是Drupal 8
的全新产品。我创建了一个节点category (taxonomy)
。现在我不明白如何通过使用nid
来获得tid
。我正在使用$node->body->value
获取正文字段值并使用{{ body }}
。但如果我使用$node->field_category->value
来获得类别ID,它将在调试模式下显示Null
。如何在Drupal 8中代表节点ID(nid)获取tid?
function THEME_preprocess_node(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
$variables['body'] = $node->body->value; // Working fine
$cat_id = $node->field_category->value; // Its showing null
kint($cat_id);
}
因此,谁能告诉我怎样才能得到一个节点的category id (tid)
?