0

I have a taxonomy term called Event type. Inside that term I have a Color field. I want to pass the HEX value of the Color field as a variable in Twig.

The taxonomy term variable in Twig (on node level) looks something like this

{{ content.field_event_type }}

So in order to access the field that exists inside that term, I would need something like this

{{ content.field_event_type.field_color_field.value }}

But I can't seem to make it work.

How do I do this? Thank you.

4
  • Does this answer your question? How to print taxonomy term field in node.html.twig?
    – leymannx
    Commented Jul 22, 2022 at 13:52
  • Swap content for node and add entity: {{ node.field_event_type.entity.field_color_field.value }}.
    – leymannx
    Commented Jul 22, 2022 at 13:53
  • @leymannx Thanks for answering. I have seen that thread and tried that code, but it's not outputting anything. I double checked that my field contains value. The value of the field is visible on the taxonomy/term/n url page. Don't know what I'm doing wrong.
    – Jay123
    Commented Jul 22, 2022 at 14:15
  • 1
    That's important info that should be in the post not in comments. You did flush the caches already I guess. Maybe we need to see more of your code.
    – leymannx
    Commented Jul 22, 2022 at 17:36

1 Answer 1

0

Just for anyone else having a brain malfunction like me and wanted to print a taxonomy term that had been selected and not 1 specific term like all the other posts, do this:

{{ node.field_name.entity.label }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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