0

I'm stuck with a probably simple problem, maybe someone can help?

I have a node (representing a route) which has a reference to other nodes (points of interestes) Like this node.field_poi

Every field_poi has it's own images attached

from the node template I'm trying to get the images, but no way!

There are my attempts, where am I wrong?

{{content.field_poi.0.entity.field_image.0.entity.uri.value}} {{kint(node.field_poi.0.entity.field_image.0.entity.uri.value)}}

If I try this, it breaks completely the page: {{kint(node.field_poi.0.entity)}}

0

Thanks to the slack channel #drupaltwig, I found a solution! I leave it here, in case somebody else needs it

{% for curr_poi in node.field_poi %}                    

{% if curr_poi.entity.field_image.entity.uri.value is not empty %}

<img class="product-image" src="{{curr_poi.entity.field_image.entity.uri.value | image_style('app_list')}}" />

{{curr_poi.entity.title.value}}

{% endif %}

{% endfor %}

Main hints:

  • use node instead of content
  • iterator is curr_poi do not use a index
  • I used twig_tweak drupal module in order to user the filter | image_style('app_list')

Thanks to @kekkis @markconroy

| improve this answer | |

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.