我是Drupal 8
的新人。我创建了一个category (taxonomy)
的节点。现在,我不了解如何使用tid
获取nid
。我使用$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)
?
答案 0 :(得分:0)
可以使用target_id而不是value来获取引用字段的值。使用target_id,您可以根据需要加载完整的术语。
from StringIO import StringIO
s="""
1,98.4,100M,55M,65M,75M,100M,75M,65M,100M,98M,100M,100M,92M,0#,0N#,
1,98.4,100M,55M,65M,75M,100M,75M,65M,100M,98M,100M,100M,92M,0#,0N#,
2,98.4,100M,55M,65M,75M,100M,75M,65M,100M,98M,100M,100M,92M,0#,0N#,
2,98.4,100M,55M,65M,75M,100M,75M,65M,100M,98M,100M,100M,92M,0#,0N#,
"""
yourfile = StringIO(s)