Score:0

how to get field image of a referenced entity in paragraph template

ee flag

I made a paragraph with a referenced entity field to a content type called "tools" Actually I can get the title and body text like that :

<h3>{{ content.field_tools_and_services.0['#node'].title.value }}</h3>
<p>{{ content.field_tools_and_services.0['#node'].body.value}}</p>

now, I need to get the field image, I tried to do something like this :

<img alt="{{ content.field_tools_and_service1[0]['#node'].field_image.get(0).alt }}"
src="{{ content.field_tools_and_service1[0]['#node'].field_image.entity.fileuri|image_style('image_format') }}"
title="{{ content.field_tools_and_service1[0]['#node'].field_image.get(0).title }}">

<img src="{{ content.field_tools_and_service1.0['#node'].values.field_image.0['#uri'] }}"
alt="{{ label.0 }}">

{{ content.field_tools_and_service1.0['#node'].field_image.value) }}

But I can't get my image, what's my mistake ?

Thanks

leymannx avatar
ne flag
Instead of doing that consider creating a new view mode for your referenced entity that just displays the fields you want (and also comes with its own template) and then simply choose the view mode for the referenced entities in the parent entity's display settings. No one should need to write image markup like that anymore.
johndoe80 avatar
ee flag
I already did it with this way, but I wanted to try do it with paragraph, I'm new to drupal, and I would like to try to do this another way to train
4uk4 avatar
cn flag
Please don't post code examples with the `|raw` filter, this is extremely dangerous. If you can't use a view mode, see https://drupal.stackexchange.com/questions/231805/filter-raw-doesnt-show-entity-media-image/231981#231981
Kevin avatar
in flag
Doing it "this way" is not a good way to train. Render things appropriately as leymannx said, that is worth learning over extended markup above.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.