# CustomFields Media Ausgabe

**URL:** <https://forum.shopware.com/t/customfields-media-ausgabe/64190>\
**Category:** Shopware 6 (German)\
**Created:** [22. Januar 2020 um 14:31 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190 "2020-01-22T14:31:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [22. Januar 2020 um 14:31 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/1 "2020-01-22T14:31:39Z")

</div>

Hallo,&nbsp;

Die Medien aus&nbsp;customFields kann ich irgendwie nicht ausgeben?!&nbsp;

Mein Versuch :&nbsp;

{{ page.product.translated.customFields.download\_1 }} Ausgabe -\>&nbsp;aebd542d56084b6ea9f1ee72701e3580

{{ dump(page.product.translated.customFields) }} gibt mir auch alle Custom Felder aber nicht die Url der Datei.&nbsp;

&nbsp;

Mit freundlichen Grüßen

Amin Nayerhabibi

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [22. Januar 2020 um 14:42 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/2 "2020-01-22T14:42:13Z")

</div>

Hallo Amin,

schau mal hier:&nbsp;[Shopware 6: Use custom fields with media type](https://docs.shopware.com/en/shopware-platform-dev-en/how-to/custom-fields-media-type)&nbsp;  
So kannst du dir eine MediaCollection holen, die die Medien enthält, die du per ID reinreichst.

Viele Grüße aus Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [22. Januar 2020 um 15:49 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/3 "2020-01-22T15:49:34Z")

</div>

[@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](http://forum.shopware.com/profile/17553/Michael) Telgmann “Michael Telgmann”)‍ Danke für die Antwort, also muss man für die Ausgabe von Medien ein Plugin schreiben? oder kann man die Funktion auch in Template Plugin reinmachen?&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [23. Januar 2020 um 06:49 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/4 "2020-01-23T06:49:55Z")

</div>

Hallo Amin,

nein, wie man am Beispiel sehen kann, wird der Code einfach in ein Twig Template eingefügt. D.h. du kannst das auch in deinem Theme Plugin so nutzen und brauchst keinen weiteren Code im Plugin.

Viele Grüße aus Schöppingen

![cool](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [24. Januar 2020 um 15:29 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/5 "2020-01-24T15:29:14Z")

</div>

> [@Michael Telgmann schrieb:](https://forum.shopware.com/profile/17553/Michael%20Telgmann "Michael%20Telgmann")
> 
> Hallo Amin,
> 
> nein, wie man am Beispiel sehen kann, wird der Code einfach in ein Twig Template eingefügt. D.h. du kannst das auch in deinem Theme Plugin so nutzen und brauchst keinen weiteren Code im Plugin.
> 
> Viele Grüße aus Schöppingen
> 
> ![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

Hallo [@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](http://forum.shopware.com/profile/17553/Michael) Telgmann „Michael Telgmann“)‍ ,

Ich habe noch ein Problem. Wenn ich diese Funktion benutze bekommen ich folgende Fehlermeldung:&nbsp;

Uncaught PHP Exception Twig\Error\SyntaxError: „Unknown „searchMedia“ function.“

```
{% set id = page.product.translated.customFields.download_1 %}
			{% set media = searchMedia([id], context.context) %}
			   {% set downloadurl = media.get(id) %}
				 {{ dump (downloadurl) }}

```

und&nbsp;MediaExtension.php gibt es bei mir nur unter&nbsp;vendor/shopware/storefront/Theme/Extension/ und hat folgende Inhalt:&nbsp;

```
add(
            (new OneToManyAssociationField('themes', ThemeDefinition::class, 'preview_media_id'))->addFlags(new ReadProtected(SalesChannelApiSource::class))
        );

        $collection->add(
            (new ManyToManyAssociationField('themeMedia', ThemeDefinition::class, ThemeMediaDefinition::class, 'media_id', 'theme_id'))->addFlags(new ReadProtected(SalesChannelApiSource::class))
        );
    }

    public function getDefinitionClass(): string
    {
        return MediaDefinition::class;
    }
	
}

```

folgende Code finde ich gar nicht bei mir, trotz Update:&nbsp;

```
public function searchMedia(array $ids, Context $context): MediaCollection
    {
        if (empty($ids)) {
            return new MediaCollection();
        }

        $criteria = new Criteria($ids);

        /** @var MediaCollection $media */
        $media = $this->mediaRepository
            ->search($criteria, $context)
            ->getEntities();

        return $media;
    }

```

Unter&nbsp;/vendor/shopware/core/Framework/Adapter/Twig/Extension/ gibt es nur eine Datei :&nbsp;SeoUrlFunctionExtension.php

fehlte vielleicht irgendwas bei der Composer Update?&nbsp;

Meine Shopware Version =&nbsp;v6.1.0 Stable Version

---

<div class="post-metadata">

**Author:** ![TomVr](https://avatars.discourse-cdn.com/v4/letter/t/51bf81/32.png) [@TomVr](https://forum.shopware.com/u/TomVr)\
**Post date:** [28. Januar 2020 um 07:55 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/6 "2020-01-28T07:55:17Z")

</div>

Hallo,

ich habe genau das selbe Problem mit der selben Fehlermeldung. Gibt es dazu schon Infos?

Mit freundlichen Grüßen

Tom

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [28. Januar 2020 um 09:35 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/7 "2020-01-28T09:35:20Z")

</div>

Hallo ihr beiden,

entschuldigt die Umstände. Das Feature ist erst mit der Version 6.1.1 rein gekommen. Diese wurde gestern veröffentlicht. Wenn ihr also ein Update durchführt, sollte das wie dokumentiert funktionieren.&nbsp;

Viele Grüße aus Schöppingen

![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [28. Januar 2020 um 13:06 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/8 "2020-01-28T13:06:10Z")

</div>

[@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](http://forum.shopware.com/profile/17553/Michael) Telgmann „Michael Telgmann“)‍ Vielen Dank hat geklappt.&nbsp; ![Thumb-Up](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/thumb-up.png "Thumb-Up") ![Shopware](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "Shopware")

---

<div class="post-metadata">

**Author:** ![mdoroci](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mdoroci](https://forum.shopware.com/u/mdoroci)\
**Post date:** [28. Januar 2020 um 16:33 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/9 "2020-01-28T16:33:47Z")

</div>

Hi

What I did is, inside:

MyPluginRoot/src/Resources/views/storefront/page/product-detail/index.html.twig

I placed this code:

 ![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/c/cd365cb9714677ac00ef9f37cbb09d8e3149ed5c.png)

I have also tried with :&nbsp;page.product.translated.customFields.custom\_test\_test (custom\_test\_test is my custom field of type media).

Should I add something else or where can be the problem?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [29. Januar 2020 um 11:21 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/10 "2020-01-29T11:21:19Z")

</div>

Hi @mdoroci‍

what is the problem on your site? Do you get some error message?

Best regards from Schöppingen

![cool](http://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/shopware.png "cool")&nbsp;Michael Telgmann

---

<div class="post-metadata">

**Author:** ![mdoroci](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mdoroci](https://forum.shopware.com/u/mdoroci)\
**Post date:** [29. Januar 2020 um 11:29 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/11 "2020-01-29T11:29:59Z")

</div>

Hi [@Michael Telgmann]([http://forum.shopware.com/profile/17553/Michael](http://forum.shopware.com/profile/17553/Michael) Telgmann „Michael Telgmann“)‍,

It shows the products, but not the media from the custom field.&nbsp;

&nbsp;

Best regards

&nbsp;

---

<div class="post-metadata">

**Author:** ![Michael\_Telgmann](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/michael_telgmann/32/20289_2.png) [@Michael\_Telgmann](https://forum.shopware.com/u/Michael_Telgmann)\
**Post date:** [29. Januar 2020 um 12:23 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/12 "2020-01-29T12:23:04Z")

</div>

are you sure, that you are on version 6.1.1 ?

---

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [29. Januar 2020 um 13:07 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/13 "2020-01-29T13:07:07Z")

</div>

@mdoroci‍&nbsp;Try the following code:&nbsp;&nbsp;download\_1 is my Custom Field and this code is for Article Detail Page (page.product.translated.customFields.Custom-Field-Name)

```
{% set download = page.product.translated.customFields.download_1 %}

  {% if download != '' %}

    {% set media = searchMedia([download], context.context) %}
    {% set downloadurl = media.get(download) %}
	
      {{ (downloadurl.url) }}
      {{ (downloadurl.fileName) }}
      {{ (downloadurl.fileExtension) }}
				 

  {% endif %}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![webman](https://avatars.discourse-cdn.com/v4/letter/w/9fc29f/32.png) [@webman](https://forum.shopware.com/u/webman)\
**Post date:** [27. Februar 2020 um 12:40 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/14 "2020-02-27T12:40:13Z")

</div>

Ich habe den Code leicht angepasst, er erzeugt jetzt einen Link pro angehangenem Media-Element:

```
{% for file in page.product.translated.customFields %}
	{% if file != '' %}
		{% set media = searchMedia([file], context.context) %}
		{% set downloadurl = media.get(file) %}
		{{ (downloadurl.fileName) }} herunterladen [{{ (downloadurl.fileExtension) }}]
	{% endif %}
{% endfor %}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![martin\_konvis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/martin_konvis/32/14370_2.png) [@martin\_konvis](https://forum.shopware.com/u/martin_konvis)\
**Post date:** [11. Juni 2020 um 15:55 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/15 "2020-06-11T15:55:39Z")

</div>

Hallo,

Leider erhalten ich auch den Fehler.&nbsp;Verwende aktuell

[https://docs.shopware.com/en/shopware-6-en/tutorials-and-faq/virtual-box-setup?category=shopware-6-en%2Ftutorials-and-faq](https://docs.shopware.com/en/shopware-6-en/tutorials-and-faq/virtual-box-setup?category=shopware-6-en%2Ftutorials-and-faq)

=\> shopware.ova // Shopware Version - “v9999999 Developer Version” wird bei mir angezeigt? Die Versionsnummer scheint mir aber fehlerhaft?

Ist die ova Datei veraltet? Wenn ich die anderen Kommentare richtig verstehe, sollte es doch eigentlich seit ein paar Monaten funktionieren?

&nbsp;

basierend auf Doku&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)

“Uncaught PHP Exception Twig\Error\SyntaxError: " **Unknown&nbsp;** “searchMedia” **&nbsp;function.** ” at"

{{ page.product.translated.customFields.custom\_test\_image\_one }} =\> zeigt mir die ID an

&nbsp;

die searchMedia funktion funktioniert aber nicht

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;{# simplify ID access #}  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{% set sportsMediaId = page.product.translated.customFields.custom\_test\_image\_one %}

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{# fetch media as batch - optimized for performance #}  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{% set mediaCollection = searchMedia([sportsMediaId], context.context) %}

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{# extract single media object #}  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{% set sportsMedia = mediaCollection.get(sportsMediaId) %}

&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{{ dump (sportsMedia) }}

Grüße

Martin

---

<div class="post-metadata">

**Author:** ![andrihuder](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@andrihuder](https://forum.shopware.com/u/andrihuder)\
**Post date:** [3. März 2021 um 14:35 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/16 "2021-03-03T14:35:01Z")

</div>

Does not work for me…  
With custom field name is meant the name of the set?![code|515x312]

 ![set](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/3/3ecb3d30c5db74d28231a8699a71f4622783df6d.png)

---

<div class="post-metadata">

**Author:** ![11shop](https://avatars.discourse-cdn.com/v4/letter/1/90ced4/32.png) [@11shop](https://forum.shopware.com/u/11shop)\
**Post date:** [11. Juni 2021 um 13:04 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/17 "2021-06-11T13:04:00Z")

</div>

No not the Attribute Group Set Name.  
I mean the Name of Custom Attribute.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/b/bd95e05b1c2ac158ffc578c81c213fa166dbe524.png)

---

<div class="post-metadata">

**Author:** ![efa\_Web\_iT](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/efa_web_it/32/15142_2.png) [@efa\_Web\_iT](https://forum.shopware.com/u/efa_Web_iT)\
**Post date:** [1. April 2022 um 05:58 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/18 "2022-04-01T05:58:13Z")

</div>

Das hat funktioniert.  
Danke!

---

<div class="post-metadata">

**Author:** ![unikatgmbh](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/unikatgmbh/32/13771_2.png) [@unikatgmbh](https://forum.shopware.com/u/unikatgmbh)\
**Post date:** [20. März 2023 um 16:44 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/19 "2023-03-20T16:44:22Z")

</div>

Hallo,  
die Ausgabe des Custom Media Fields geht bei mir auf der Produktdetailseite einwandfrei.

Wenn ich das aber in der Listenansicht z.B. unter /component/product/card/box-standard.html.twig verwenden möchte, bricht das Template an der Stelle ab und wird nicht weiter ausgeführt. Ohne Fehlermeldung auf der Seite oder im Log.

Gibt es auf dieser Seite eine andere Möglichkeit ein Custom Media Field im Template auszugeben?

VG Björn

---

<div class="post-metadata">

**Author:** ![CptPicard](https://avatars.discourse-cdn.com/v4/letter/c/a587f6/32.png) [@CptPicard](https://forum.shopware.com/u/CptPicard)\
**Post date:** [18. August 2023 um 13:47 UTC](https://forum.shopware.com/t/customfields-media-ausgabe/64190/20 "2023-08-18T13:47:40Z")

</div>

Moin Björn,

wenn das noch relevant sein sollte, ja, das geht.  
Bei der Referenzierung bei Listen einfach auf das „page“ verzichten. Also statt page.product.translated.customFields.eigenes\_feld einfach product.translated.customFields.eigenes\_feld verwenden. „page“ wird scheinbar nur auf Produktdetailseiten verwendet.

Beste Grüße
