Drupal - How to get the human readable content type name in a node template

You should be able to get the human-readable name of the content type (or the "label") by using the following snippet in your node Twig template.

{{ node.type.entity.label }} 

You can add the human readable name of the content type in a preprocess hook:

mytheme.theme

use Drupal\node\Entity\NodeType;

/**
 * Implements hook_preprocess_node().
 */
function mytheme_preprocess_node(array &$variables) {
  $node = $variables['node'];
  $variables['content_type'] = NodeType::load($node->bundle())->label();
}

and use it in the node template:

{{ content_type }}

Tags:

Nodes

Theming

8