# Twig macro oder sw\_include

**URL:** <https://forum.shopware.com/t/twig-macro-oder-sw-include/62294>\
**Category:** Themes & Design\
**Created:** [11. Oktober 2019 um 07:35 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294 "2019-10-11T07:35:39Z")\
**Posts on this page:** 5\
**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:** [11. Oktober 2019 um 07:35 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294/1 "2019-10-11T07:35:39Z")

</div>

Hallo, ich habe ein twig-macro erstellt, es wird nur nicht ausgeführt. Wird macro überhaupt unterstützt ? Falls nicht, kann ich mit sw\_include einen bestimmten Block einer Twig-Datei aufrufen? Ich baue mir gerade ein Menu mit Submenu. Danke und Gruss

---

<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:** [12. Oktober 2019 um 19:46 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294/2 "2019-10-12T19:46:37Z")

</div>

Vll stelle ich die Frage nochmal anders. In Smarty konnte man ja Funktions-Blöcke „call“-en, geht das irgendwie mit Twig auch? Im Moment habe ich den Aufruf eines solchen Blocks als sw-include, finde es aber unpraktisch 2 Dateien zu haben. Geht da was? Danke und Gruss.

---

<div class="post-metadata">

**Author:** ![Shopwareianer](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Shopwareianer](https://forum.shopware.com/u/Shopwareianer)\
**Post date:** [12. Oktober 2019 um 19:58 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294/3 "2019-10-12T19:58:21Z")

</div>

Vielleicht suchst du eher eine Twig Extension, als nen macro? =\>&nbsp;[https://symfony.com/doc/current/templating/twig\_extension.html](https://symfony.com/doc/current/templating/twig_extension.html)

---

<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:** [12. Oktober 2019 um 20:08 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294/4 "2019-10-12T20:08:30Z")

</div>

Hallo @Shopwareianer‍ &nbsp;.Ein Macro habe ich ja schon erstellt und das ging nicht. Ich ging davon aus, dass es wie folgt funktioniert:

```
{% macro abc() %}
   Hallo Welt
{% endmacro %}

{% _self.abc() %}

```

Muss man dazu Twig extra Extenden oder geht das von haus aus und ich hab nur was falsch gemacht?&nbsp;

---

<div class="post-metadata">

**Author:** ![Shopwareianer](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@Shopwareianer](https://forum.shopware.com/u/Shopwareianer)\
**Post date:** [12. Oktober 2019 um 20:39 UTC](https://forum.shopware.com/t/twig-macro-oder-sw-include/62294/5 "2019-10-12T20:39:11Z")

</div>

Du rufst falsch auf.

Es muss **{{ \_self.abc() }}** sein. Also {{ nicht mit {%

Ansonsten kannst du macros natürlich auch auslagern und dann importieren =\>&nbsp;[https://twig.symfony.com/doc/2.x/tags/macro.html#importing-macros](https://twig.symfony.com/doc/2.x/tags/macro.html#importing-macros)
