Score:0

How to display taxonomy field value in paragraph twig file?

mx flag

How to display role taxonomy field value in paragraph--user-category.html.twig file? Field structure: field_role-> role taxonomy field.

I can print by {{ content.field_role | raw }} But I need to display value text only.

I tried below the code and not working. Please advise. {{ paragraph.field_role.entity.value }}

Printed value: {{ dump(paragraph.field_role) }}

enter image description here

Score:1
cn flag

I tried below the code and not working. Please advise.

{{ paragraph.field_role.entity.value }}

You say you need to display a value text only, but the referenced taxonomy term entity paragraph.field_role.entity doesn't have a .value. Taxonomy terms have a name:

{{ paragraph.field_role.entity.getname }}

You can get the .id as well and any field value .field_foo.value.

Translation

If you have a multilingual site you need to translate the referenced entities:

{{ paragraph.field_role.entity|translation.getname }}

Install Twig Tweak in this case.

See https://git.drupalcode.org/project/twig_tweak/-/blob/3.x/docs/cheat-sheet.md#entity-translation

Ramalingam Perumal avatar
mx flag
`getname` working fine. Thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.