# EMail Templates: How to include thumbnails?

**URL:** <https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628>\
**Category:** Themes & Design (EN)\
**Created:** [18. Dezember 2020 um 10:03 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628 "2020-12-18T10:03:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nagodi](https://avatars.discourse-cdn.com/v4/letter/n/f04885/32.png) [@nagodi](https://forum.shopware.com/u/nagodi)\
**Post date:** [18. Dezember 2020 um 10:03 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628/1 "2020-12-18T10:03:19Z")

</div>

Hello!

The email templates, esp. order confirmation and updates, should contain thumbnails of the lineitems. The mediaId is saved in **lineItem.coverId**.

&nbsp;

I have tried to solve it with the&nbsp;&nbsp;\*\*searchMedia()&nbsp;\*\*function&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

```
{# search for media in database #}
{% set media = searchMedia([lineItem.coverId], context.context) %}

{# extract mediaentity object #}
{% set mediaEntity = media.get(lineItem.coverId) %}

 {# get url #}
 {% set mediaUrl = mediaEntity.getUrl() %}
{{mediaUrl}}

```

=\> official docu:[&nbsp;https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-fields-media-type](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-fields-media-type)  
=\> discussion:&nbsp;[https://forum.shopware.com/discussion/65543/customfields-media-ausgabe](https://forum.shopware.com/discussion/65543/customfields-media-ausgabe)

The problem seems to be that the **context** isn’t existing in the mail templates. Also, there is an empty output when I am using&nbsp;**{{ dump() }}&nbsp;**; although the environment is set to DEV mode

Do you have any ideas how to solve this?  
How do you include the images? Or how do you get the image url?

Thanks!

---

<div class="post-metadata">

**Author:** ![kanuma](https://avatars.discourse-cdn.com/v4/letter/k/ce7236/32.png) [@kanuma](https://forum.shopware.com/u/kanuma)\
**Post date:** [20. Januar 2021 um 13:03 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628/2 "2021-01-20T13:03:33Z")

</div>

Any new regarding this issue?

---

<div class="post-metadata">

**Author:** ![fds](https://avatars.discourse-cdn.com/v4/letter/f/8dc957/32.png) [@fds](https://forum.shopware.com/u/fds)\
**Post date:** [3. Juni 2021 um 14:07 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628/3 "2021-06-03T14:07:25Z")

</div>

As mentioned in another issue: [Bilder in Email-Bestätigungen - #12 von FloC3](https://forum.shopware.com/t/bilder-in-email-bestatigungen/66455/12)  
This worked for me

```
<img src="{{ searchMedia([lineItem.coverId], context).first()|sw_encode_media_url }}" width="100" />
```

---

<div class="post-metadata">

**Author:** ![abart\_owidmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abart_owidmann/32/14628_2.png) [@abart\_owidmann](https://forum.shopware.com/u/abart_owidmann)\
**Post date:** [18. Dezember 2021 um 17:34 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628/4 "2021-12-18T17:34:13Z")

</div>

This is great - now we have the URL! 🙂 But is there a possibility to take the pre-generated thumbnails (e.g. 100px), like with sw\_thumbnails?

---

<div class="post-metadata">

**Author:** ![lunex](https://avatars.discourse-cdn.com/v4/letter/l/5e9695/32.png) [@lunex](https://forum.shopware.com/u/lunex)\
**Post date:** [14. September 2023 um 15:58 UTC](https://forum.shopware.com/t/email-templates-how-to-include-thumbnails/71628/5 "2023-09-14T15:58:28Z")

</div>

```auto
{% set id = lineItem.coverId %}
{% set mediaCollection = searchMedia([id], context) %}
{% set mediaImage = mediaCollection.get(id) %}

{% for item in mediaImage.thumbnails.elements %}
{% if item.width == 190 %}
  <img src="{{ item.url }}">
{% endif %}
{% endfor %}

```

I dumped it inside my base.html.twig. To test and look around. I got it to work there with sw\_thumbnails. But got an [object Promise] error. So I looked further in the information my dump gave me and came up with this solution. You can replace the 190 with any other thumbnail resoulution your shop gives you.
