0

I'm kind of a twig newbie so I'm hoping that someone can point me in the right direction.

I've added a custom field field_url to a taxonomy type called field_type_poi. How would you render that taxonomy type's individual field in node.html.twig?
I know that I can use {{ content.field_type_poi }} to render the entire contents of the taxonomy type, but I'm looking for a way to render one field specifically.

1 Answer 1

1

{{ content.field_type_poi }} doesn't necessarily render the entire content of the taxonomy term. You can select the field in the tab Manage Display where you've added the field field_url to the vocabulary.

If you need multiple field selections, here only this field, but in all other places the default selection, then add a custom view mode in Custom Display Settings at the bottom of the page.

Finally go to the content type and configure the field field_type_poi in the tab Manage Display to be rendered in the view mode you've configured above.


Edit:

If you want to use different fields from the taxonomy in different locations you would need to clone the field, see Show field twice in node page, or install the module Twig Tweak and render single fields in Twig:

{% set tid = node.field_type_poi.target_id %}
{% if tid %}
  {{ drupal_field('field_url', 'taxonomy_term', tid) }}
{% endif %}
1
  • Thank you for your reply! I had thought about doing it that way, but I was hoping there was a way to render each field individually where needed. The reason being, we potentially wanted to use different fields from the taxonomy in different locations, without having to create a new view-mode and render it for each scenario. Thank you for answering my question!
    – RundleSG
    Commented Mar 24, 2019 at 15:37

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.