# Add to your service definition a method call to setTwig with the twig instance

**URL:** <https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535>\
**Category:** Shopware 6 (German)\
**Created:** [3. Mai 2023 um 16:12 UTC](https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535 "2023-05-03T16:12:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [3. Mai 2023 um 16:12 UTC](https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535/1 "2023-05-03T16:12:38Z")

</div>

Hallo,

ich bekomme mit Shopware 6.5 in einem Plugin bei einer Controller Action jetzt …

# Class MyVendor\Controller\Storefront\MyExampleController does not have twig injected. Add to your service definition a method call to setTwig with the twig instance

Die Fehlermeldung wird dadurch geworfen:  
return $this-\>renderStorefront(‚storefront/page/product-detail/my\_example/product-example-form.html.twig‘, [  
‚productId‘ =\> $productId,  
‚saveSuccess‘ =\> 1  
]);

Die Annotation Route:  
@Route(„/my\_vendor/saveexample/{productId}“, name=„frontend.detail.save-example“, methods={„POST“}, defaults={„XmlHttpRequest“=true})

Unter 6.4 ging noch alles einwandfrei. Was muss unter 6.5 geändert werden, damit im Controller das Twig-Template wieder gerendert wird.

Gruss

---

<div class="post-metadata">

**Author:** ![magnolia4gmbh](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/magnolia4gmbh/32/13167_2.png) [@magnolia4gmbh](https://forum.shopware.com/u/magnolia4gmbh)\
**Post date:** [3. Mai 2023 um 20:42 UTC](https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535/2 "2023-05-03T20:42:36Z")

</div>

Du musst in deiner services.xml einen call bei deinem Controller-Service hinzufügen:

```auto
            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
            <call method="setTwig">
                <argument type="service" id="twig"/>
            </call>

```

---

<div class="post-metadata">

**Author:** ![Liverson](https://avatars.discourse-cdn.com/v4/letter/l/b19c9b/32.png) [@Liverson](https://forum.shopware.com/u/Liverson)\
**Post date:** [4. Mai 2023 um 07:22 UTC](https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535/3 "2023-05-04T07:22:10Z")

</div>

> [@magnolia4gmbh](#):
>
> ```auto
> <call method="setTwig">
> <argument type="service" id="twig"/>
> </call>
> 
> ```

Danke, das wars tatsächlich, war mit 6.4 noch nicht nötig, da war der Service scheinbar automatisch verfügbar

---

<div class="post-metadata">

**Author:** ![daslicht](https://avatars.discourse-cdn.com/v4/letter/d/b5ac83/32.png) [@daslicht](https://forum.shopware.com/u/daslicht)\
**Post date:** [6. November 2023 um 13:07 UTC](https://forum.shopware.com/t/add-to-your-service-definition-a-method-call-to-settwig-with-the-twig-instance/99535/4 "2023-11-06T13:07:52Z")

</div>

Das sollte [hier](https://developer.shopware.com/docs/guides/plugins/plugins/storefront/add-custom-controller.html) in die Dhopware 6.5 (latest) Dokumentation aufgenommen werden.

Dokumentation:

```auto
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="Swag\BasicExample\Storefront\Controller\ExampleController" public="true">
            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
        </service>
    </services>
</container>

```

Solle sein:

```auto
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services" 
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>
        <service id="Swag\BasicExample\Storefront\Controller\ExampleController" public="true">
            <call method="setContainer">
                <argument type="service" id="service_container"/>
            </call>
            <call method="setTwig">
                <argument type="service" id="twig"/>
            </call>
        </service>
    </services>
</container>

```
