# Custom twig funktion hinzufügen

**URL:** <https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285>\
**Category:** Shopware 6 (German)\
**Created:** [16. Januar 2025 um 16:14 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285 "2025-01-16T16:14:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [16. Januar 2025 um 16:14 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/1 "2025-01-16T16:14:06Z")

</div>

Hi,  
ich wollte im Twig mit md5 arbeiten.  
Dazu habe ich diese Anleitung befolgt: [Add Custom Twig Functions | Shopware Documentation](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-twig-function.html)  
Aber ich bekomme ein halbleeres Frontend und ein Error 500 im Backend.

```auto
Did you forget a \u0022use\u0022 statement for another namespace?

```

Weiss jemand was das bedeutet?

Danke und Gruss

---

<div class="post-metadata">

**Author:** ![Anotherone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anotherone](https://forum.shopware.com/u/Anotherone)\
**Post date:** [16. Januar 2025 um 21:35 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/2 "2025-01-16T21:35:51Z")

</div>

Ich vermute mal, Du verwendest eine Funktion/Klasse einer anderen Datei ohne das nötige use Statement. Normalerweise sollte die Klasse in der Fehlermeldung auch benannt werden.

---

<div class="post-metadata">

**Author:** ![WebentwicklSchaefer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/webentwicklschaefer/32/27230_2.png) [@WebentwicklSchaefer](https://forum.shopware.com/u/WebentwicklSchaefer)\
**Post date:** [17. Januar 2025 um 05:56 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/3 "2025-01-17T05:56:12Z")

</div>

Hallo @brettvormkopp ,

schau dir nochmal den Teil an:

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

Würde vermuten hast davon eines vergessen oder eine andere Klasse aufgerufen welche ebenfalls per use hinzugefügt werden muss. Anhand der genannten Fehlermeldung alleine kann dir aber keiner sagen was genau vergessen wurde.

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [17. Januar 2025 um 07:24 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/4 "2025-01-17T07:24:42Z")

</div>

Ich habe copy/paste der Anleitung gemacht. Nach theme:compile und cache:clear kommt im backend der fehler:

```auto
{"errors":[{"code":"0","status":"500","title":"Internal Server Error","detail":"Attempted to load class \u0022SwagCreateMd5Hash\u0022 from namespace \u0022SwagBasicExample\\Twig\u0022.\nDid you forget a \u0022use\u0022 statement for another namespace?"}]}

```

Im Frontend ist das Listing leer. Der Rest drumherum wird angezeigt.

EDIT: Hinweis Ich nutze das in meine Plugin Theme.

---

<div class="post-metadata">

**Author:** ![WebentwicklSchaefer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/webentwicklschaefer/32/27230_2.png) [@WebentwicklSchaefer](https://forum.shopware.com/u/WebentwicklSchaefer)\
**Post date:** [17. Januar 2025 um 11:26 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/5 "2025-01-17T11:26:38Z")

</div>

@brettvormkopp - Irgendwas mit den Namespaces oder Klassennamen stimmt nicht überein.  
Heisst dein Plugin „SwagBasicExample“? Falls nicht könnte da evtl. eine Anpassung notwendig sein.

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [17. Januar 2025 um 12:48 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/6 "2025-01-17T12:48:08Z")

</div>

Das Theme Plugin in dem diese Twig erweiterung steckt heisst anders.

- /src/SwagBasicExampleTheme.php

Die Twig Erweiterung ist in diesem Theme Plugin unter

- /src/Twig/SwagCreateMd5Hash.php
- /src/Resources/config/services.xml

---

<div class="post-metadata">

**Author:** ![WebentwicklSchaefer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/webentwicklschaefer/32/27230_2.png) [@WebentwicklSchaefer](https://forum.shopware.com/u/WebentwicklSchaefer)\
**Post date:** [17. Januar 2025 um 15:56 UTC](https://forum.shopware.com/t/custom-twig-funktion-hinzufuegen/106285/7 "2025-01-17T15:56:35Z")

</div>

@brettvormkopp - Dann wird dann nehme ich an der Fehler sein.

Steht hier dein Theme-Name?

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/e/f/ef603c10b7b25d08d5fc80654a70a8f772d999a5.png)

Falls nicht das mal eintragen - Ohne den ganze Quellcode ist das ganze etwas „schwierig“ die genaue Stelle zu finden. Wenn es das nicht ist, dann sende mir gerne mal den Quellcode zu (das würde das ganze einfacher machen).

Viele Grüße  
Marco

_PS: Bitte bei Antwort erwähnen, da ich sonst nicht benachrichtigt werde._
