0

I would like to get the pretty value from a field in my content.

Here is the structure of the select box field when I add a content :

00|Ground
01|Apartment
02|House / Cottage
03|Business premises
06|Attachments

In my node--content-type.html.twig, when I call the field with :

content.field_*machine_name*.value

It display the key of the selection (00, 01, 02,...). I would like to have Apartment, House / Cottage, ....

When I call just this :

content.field_*machine_name*

It display the pretty value but wrapped in a div that I don't want.

3

When I call just this :

content.field_*machine_name*

It display the pretty value but wrapped in a div that I don't want.

This is the correct way, you should if possible render a field in node twigs like this.

The div, that you don't want, is probably in the field twig, that gets invoked by using {{ content.field_*machine_name* }}.

You have to put a copy of field.html.twig in your theme and name it:

field--field_*machine_name*.html.twig

And look there for the div.

0

Try adding the "raw" filter:

{{ content.field_examplefield|raw }}

Also, make sure to hide label at

/admin/structure/types/manage/example_content_type/display

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.