I am new in Drupal 8
. I have created a node with category (taxonomy)
. Now I don't understand how to get tid
by using nid
. I am using $node->body->value
to get the body field value and use {{ body }}
. But to get category id if I use $node->field_category->value
, it will display Null
in debugging mode.
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);
}
So can anyone please tell me how can I get the category id (tid)
of a node?