Question

Hoping someone can assist me please.

I am trying to display the value of a custom field in a bootstrap sub theme

I have created my node--testtype.html.twig template and that seems to work.

I'm trying to just show the content of one field, the machine name is field_classification.

When I use <h1>Classification: {{ content.field_classification.value }}</h1> the Classification displays as expected, but the value of my field_classification doesn't.

Can anyone see what I am doing wrong please as thought I d copied the correct code from what I have read?

Was it helpful?

Solution

{{ content }} is a render array and does not have a .value, just use {{ content.field_name }}

You only need the .value when you want to print the raw values of an entity object like node, e.g. {{ node.field_my_integer.value }}

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top