Reputation: 1480
I'm trying to display sub fields of a multi value entity reference.
Tried:
{% for item in node.field_related_items %}
{{ item.content['#node'].field_author.value }}
{% endfor %}
Also:
{% for item in content.field_related_items %}
{{ item.field_author }}
{% endfor %}
If I do the following:
{% for item in node.field_related_items %}
{% set img1 = item.entity.field_featured_image %}
{{ img1 }}
{% set label1 = item.entity.label %}
{{ label1 }}
{% endfor %}
The label works, but not the image...
Same thing with:
item.entity.field_featured_image.value
No success,
Still not sure how to display sub fields of the entity reference...
Please help!
Upvotes: 0
Views: 3561
Reputation: 1480
The answer to image, taxonomy, links and plain fields templating:
{% for item in node.field_related_items %}
<div class="col-sm-12 col-md-4">
<div class="img-wrap">{{ file_url(item.entity.field_featured_image.entity.uri.value) }} </div>
{% set cat1 = item.entity.field_blog_category.entity.label %}
<div class="cat-wrap">{{ cat1 }}</div>
{% set label1 = item.entity.label %}
<div class="title-wrap">{{ label1 }}</div>
{% set aut1 = item.entity.field_author.value %}
<div class="author-wrap">By <span>{{ aut1 }}</span> |
{% set date1 = item.entity.field_publish_date.value %}
{{ date1 }}</div>
<a href="{{ path('entity.node.canonical', {'node': item.entity.id}) }}">Link</a>
</div>
{% endfor %}
Upvotes: 1