0

Here is my use case: I have a content type which has a field referencing multiple other entities. Those entities have a text field with multiple values.

So I do

{% for ref in node.field_references %}

and then inside the loop

ref.entity.title.value

To have the title of the referenced entity. This works. Then I try to list the values in the text field:

for value in ref.entity.field_name_of_text_field

But without success. Is there something else that must be done first?

1

Both loops iterate field items, so when you name the loop variables accordingly the code should be more understandable:

{% for ref_item in node.field_references %}
  {% for text_item in ref_item.entity.field_name_of_text_field %}
    {{ text_item.value }}
  {% endfor %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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