【发布时间】:2016-07-22 07:17:58
【问题描述】:
我是Drupal 8 的新手。我用category (taxonomy) 创建了一个节点。现在我不明白如何使用nid 获得tid。我正在使用$node->body->value 获取正文字段值并使用{{ body }}。但是如果我使用$node->field_category->value来获取类别ID,它将在调试模式下显示Null。
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)?
【问题讨论】:
标签: drupal-modules drupal-theming drupal-8 drupal-taxonomy