+31 20 - 261 14 99
hi@lucius.digital

Mr Treublaan 1-3
1097 DP Amsterdam
The Netherlands

How to get the 'image field url' from a referenced node in a Drupal Twig node template

06 Nov, 2021 Drupal

Home Blog How to get the 'image fie...

After quite some Google searching I found some answers that came close, but nothing that worked straight away. So to prevent you from puzzling and searching, here is how to get the image field url from a referenced node in a Twig node template

Use this code for example in node--blog--teaser.html.twig :

 

<img src="{{ file_url(node.field_REFERENCE.entity.field_IMAGE.entity.uri.value) }}" 
     alt="{{ node.field_REFERENCE.entity.field_IMAGE.entity.alt.value }}" />

Replace 'field_REFERENCE' with your node reference field system name, and replace 'field_IMAGE'  with the system name of your image field.

And by the way: more on Twig file naming conventions in Drupal here.

Drupal theming Planet Drupal
Written by Joris Snoek | Nov 06, 2021

Join the conversation

Got some more time?

Related content
07 Jun, 2021 Drupal

Programmatically in multiple Views


02 Jun, 2021 Drupal


25 May, 2021 Drupal

With new features like: @-mentions, drag-and-drop images & general settings.


Let's Talk

Pease tell me all about your project.
+31 (0)20 - 261 14 99  /  joris@lucius.digital.