2

In my node--content_type.html.twig template file, I can output both the label AND value of a field by using:

{{ content.field_title }}

I can also render just the label of a field with:

{{ content.field_title['#title'] }}

So far, so good.

However, how can I output only the VALUE of a field using the content array? I've tried:

{{ content.field_title['#value'] }}

And:

{{ content.field_title.value }}

To no avail.

Thank you for any help.

4

To get the field value without the label:

{{ content.field_name[0] }}

BONUS

If your field allows for multiple values, just increase the 0 to get the other values.

{{ content.field_name[1] }} {{ content.field_name[2] }} ... and so on.

1

I've created this module that lets you print the field label and field value individually: https://www.drupal.org/sandbox/sutharsan/2763183

<strong>{{ content.field_name|field_label }}</strong>: {{ content.field_name|field_value }}

Let me know if it is useful to you I will promote it to a full project.

0

You could use {{ dump(your_field) }} which debug show all value in field. Remember you need setting Debugging Twig template

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.