3

I have a content type (appel_offre) with a field_categorie_avis field, which is a list type with these values.

  • ouvert | Ouvert toute l'année
  • restreint | Restreint 24h
  • concurrence | Appel public à concurrence

In the node--appel-offre.html.twig template, I want to print this field but I only get the key, not the value. For example, for Appel public à concurrence, I always get concurrence.

I am using node.field_categorie_avis.value. Is there another way to get the same value?

  • what does it spit out if you use dump() on the field? – Matt Dec 29 '16 at 20:07
  • Hello and happy new years ! – lchabrand Jan 2 '17 at 0:29
  • Happy New year to you too! – Matt Jan 4 '17 at 15:57
8

You can use

{{ content.field_categorie_avis[0]['#markup'] }}

to display label.

Dont miss the [0] because drupal always store items in array in case of field size limit change.

  • Very useful. I was struggling with this for last couple of hours. – user3560198 Apr 25 '18 at 11:26

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.