0

I'm working with Drupal 8.

I have a content type called Lawyer.

This content type has an Entity reference called Firm.

In Firm (which is another content type) I have a Paragraph with an image field in it.

I need to render this image inside node--lawyer.html.twig

I have tried several ways to do it but I can't make it work. Any help?

3

Assumming a firm content type has field_paragraph which holds field_image of 1 image

for comparison to get firm name in twig file you will use

{{node.field_firm.entity.title.value}}

for firm paragraph image field value

{{node.field_firm.entity.field_paragraph.entity.field_image.entity.uri.value}}

To get the rendered image

{% 
  set firm_image = {
    '#theme':      'image_style',
    '#style_name': 'thumbnail',
    '#uri':        node.field_firm.entity.field_paragraph.entity.field_image.entity.uri.value,
    '#attributes': { class: 'yourclass' },
  } 
%}
{{firm_image}}

Alternative way to get referenced entity fields

| improve this answer | |
  • This is a new solution to me, can I basically create a fake render array in Twig by creating an array with a '#theme' key? – Hudri Apr 16 '18 at 9:45
  • Thank you so much for your help, it works perfectly! :D You made my day – Patty Apr 16 '18 at 10:46

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.