0

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.

4
  • You need to append .entity.field_image.entity.uri.value to the media image field and use filerul(). See drupal.stackexchange.com/questions/251441/…
    – 4uk4
    Dec 12, 2020 at 10:22
  • And never use ' |raw' . For a field containing HTML use ' processed_text' . See drupal.stackexchange.com/questions/231805/…
    – 4uk4
    Dec 12, 2020 at 10:23
  • Thanks. node is not an available variable on the paragraph template. so .entity.field_image.entity.uri.value won't work. How would you implement it?
    – Biok
    Dec 13, 2020 at 16:06
  • I didn't mention a node. Your question ends with a media image field which doesn't work for you and I suggested to append this code to the field. The link is only for further explanation what the code is doing.
    – 4uk4
    Dec 13, 2020 at 17:40

1 Answer 1

1

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 ) }}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.