Get image of taxonomy term of referenced content type B in content type A twig template

03/07/2018


I’m trying to display an image in a twig template. My content is organized as follows:

I have a content type A (‘Lesson’) that has an entity reference field that references a content type B (‘Series’). Content type B (‘Series’) has a taxonomy term field (‘Subject’) that belongs to a vocabulary that has the name of the term (i.e. ‘physics’), and an image field.

What I’m trying to accomplish is displaying the image associated to that term of content type B in a template for content type A (‘Lesson’).

The pseudo code would be something like this:

In a twig template for content type A
– Get associated series.
– Get the value of subject in that series.
– Get the value of the image associated to that subject.

I’ve tried syntaxes like these, but I can’t make it work:

{{ content.field_associated_series.entity.field_subject.entity.field_subject_image }}
{{ content.field_associated_series.entity.field_subject.entity.field_subject_image.value }}
{{

Hope my explanation is clear enough.

Thanks!

قالب وردپرس