Score:-2

Unable to pull image inside twig file

us flag

I am trying to show image via view twig file and below is my lin eof code:

<img width="220" height="112" src="{{ file_url(content.field_thumbnail_new[key]['#item'].entity.uri.value )}}" alt="{{ item.alt }}" />

When inspecting, I see the below:

enter image description here

any help on how this can be fixed pls?! I am using D9.

Kevin avatar
in flag
Why is this not rendered normally?
Rick avatar
us flag
I'm not sure. But per the recommended link, I added URL image formatter and added the field as {{ fields.field_thumbnail_new.content }} on my twig. Also I changed the image as "image URI" in view field settings. It worked.
Score:1
cg flag

I would recommend to use https://www.drupal.org/project/twig_tweak module.

<img src="{{ drupal_field('field_thumbnail_new', 'node', node.id, {type: 'image_url', settings: {image_style: 'YOUR_IMAGE_STYLENAME'}}) }}"  />
Rick avatar
us flag
Thanks! I have added a comment on how i fixedit
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.