# Artikel-Eigenschaft und Twig-Template: "media" is null, "mediaId" enthält eine uuid

**URL:** <https://forum.shopware.com/t/artikel-eigenschaft-und-twig-template-media-is-null-mediaid-enthalt-eine-uuid/66141>\
**Category:** Programmierung\
**Created:** [8. April 2020 um 17:14 UTC](https://forum.shopware.com/t/artikel-eigenschaft-und-twig-template-media-is-null-mediaid-enthalt-eine-uuid/66141 "2020-04-08T17:14:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgschwender](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@bgschwender](https://forum.shopware.com/u/bgschwender)\
**Post date:** [8. April 2020 um 17:14 UTC](https://forum.shopware.com/t/artikel-eigenschaft-und-twig-template-media-is-null-mediaid-enthalt-eine-uuid/66141/1 "2020-04-08T17:14:09Z")

</div>

Ich möchte in meinem Template für die product-detail Seite bei einigen Eigenschaften das hinterlegte Bild ausgeben. Die Eigenschaftsgruppe hat als „Darstellung der Ausprägungwahl“ den Wert „Bild“ hinterlegt.

- Im Twig-Template itteriere ich über ‚page.product.sortedProperties‘&nbsp;
- Am „option“ Objekt ist „media“ leider null. „mediaId“ enthält eine UUId…
- Wenn ich versuche anhand der Media-ID das Medienobjekt zu [laden](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-fields-media-type?_ga=2.239410371.1754895106.1586362351-340568724.1585834545) erhalte ich folgenden Fehler:

> An exception has been thrown during the rendering of a template („Inconsistent argument for Criteria. Please filter all invalid values first.“).

Hat jemand eine Idee warum das Bild nicht automatisch enthalten ist? Oder wie ich an das Bild heran komme?

---

<div class="post-metadata">

**Author:** ![ottscho](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@ottscho](https://forum.shopware.com/u/ottscho)\
**Post date:** [8. April 2020 um 20:19 UTC](https://forum.shopware.com/t/artikel-eigenschaft-und-twig-template-media-is-null-mediaid-enthalt-eine-uuid/66141/2 "2020-04-08T20:19:32Z")

</div>

Zeig mal dein Code. Über die uuid solltest du eig. an die Media URL kommen.

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

                            {# extract mediaentity object #}
                            {% set pdfMediaEntity = media.get(pdfMediaId) %}

                            {# get url and filename #}
                            {% set pdfMediaUrl = pdfMediaEntity.getUrl() %}
                            {% set pdfMediaFileName = pdfMediaEntity.getFileName() %}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![claudio](https://avatars.discourse-cdn.com/v4/letter/c/7cd45c/32.png) [@claudio](https://forum.shopware.com/u/claudio)\
**Post date:** [8. April 2020 um 21:52 UTC](https://forum.shopware.com/t/artikel-eigenschaft-und-twig-template-media-is-null-mediaid-enthalt-eine-uuid/66141/3 "2020-04-08T21:52:01Z")

</div>

Alternativ könntest du dich hier in das Event (ProductLoaderCriteriaEvent) einklinken&nbsp;

[https://github.com/shopware/platform/blob/87fc9e8cf4cdab0650e0caaf9a8ba12bab2902c2/src/Storefront/Page/Product/ProductLoader.php#L86](https://github.com/shopware/platform/blob/87fc9e8cf4cdab0650e0caaf9a8ba12bab2902c2/src/Storefront/Page/Product/ProductLoader.php#L86)

und die Relation hinzufügen. Dann ist media auch direkt gefüllt:

```
$criteria->addAssociation('properties.media');

```

&nbsp;
