TransWikia.com

How to display custom fields of taxonomy in field twig

Drupal Answers Asked by bb2j3z on January 6, 2022

In my content type for Event, I have an entity reference called Speakers which refers to a taxonomy called Team Members. It’s set to multiple so I can say which speakers belong to my event. On the event detail page, I want to list the speakers out with all of their fields.

I have a field hook called field-field-speakers.html which lists all of the speakers. I can’t seem to get any of the fields within the taxonomy. (ex: item.content.field_job_title ). It doesn’t display any content.

  {% for item in items %}

        <div class="member">

            <div class="name-box">
                <div class="name">

                 {{ item.content }}</div>
                <div class="position">{{ item.content.field_job_title }}</div>

            </div>
        </div>  


  {% endfor %}

How do I do this? I think the answer might be in a View but not sure how to map it dynamically based on which event I am in.

One Answer

You can use item.content['#options'].entity.field_job_title.value to get the value of the job_titlefield value, I don't know if this is the best way to do it.
So your code will be something like:

{% for item in items %}

  <div class="member">
    <div class="name-box">
      <div class="name">
        {{ item.content }}</div>
      <div class="position">{{ item.content['#options'].entity.field_job_title.value }}</div>
    </div>
  </div>

{% endfor %}

Answered by berramou on January 6, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP