Question

I have been working on this for 2 days and I can't figure it out. I hope someone can help me. I have a paragraph (dinamic_columns_grid) that has an entity reference field to another paragraph (field_dinamic_column) This nested paragraph has an entity reference field to a Media image field (field_image). All the paragraphs have more fields but this is the one that is giving me problems.

I created a twig template for the first paragraph (paragraph--dinamic-columns-grid.html.twig) where I want to display the nested paragraph's fields individually. I know I could use {{ content.field_dinamic_column }} to display all of the results, and it does work, including the image field, but that's now what I want. All the fields in the code below are displaying correctly except the image field (field_image). I have tried everything but I can't seem to make it work. Any help will be appreciate.


        {% for key, item in content.field_dinamic_column %}
            {{ item['#paragraph'].field_html_content.value|raw }} / text field.It works
            {{ item['#paragraph'].field_hide.value|raw }} / select field. It Works
            {{ item['#paragraph'].field_image }} / Media image field. It doesn't work 
         {% endfor %}

I like to be able to see the image or at the very least the url. Thanks.

Was it helpful?

Solution

After many attempts I finally figure it out, thanks to the comments above and a little investigation. I think my problem was that I assume that the machine name I need it to use for my nested image field was the one I give when I created the content type but that's not the case, I had to use the field of the media type in my case field_media_image instead of field_image.Below is the working code.

{{ file_url( item['#paragraph'].field_image.entity.field_media_image.entity.uri.value ) }}

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top