0

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

4
  • 2
    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.
    – leymannx
    Commented Oct 7, 2022 at 13:05
  • 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
    – johndoe555
    Commented Oct 7, 2022 at 13:16
  • Please don't post code examples with the |raw filter, this is extremely dangerous. If you can't use a view mode, see drupal.stackexchange.com/questions/231805/…
    – 4uk4
    Commented Oct 8, 2022 at 12:02
  • 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.
    – Kevin
    Commented Oct 10, 2022 at 13:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.