# Dokument Template durch Plugin erweitern

**URL:** <https://forum.shopware.com/t/dokument-template-durch-plugin-erweitern/92110>\
**Category:** Programmierung\
**Tags:** programming\
**Created:** [28. Dezember 2021 um 13:11 UTC](https://forum.shopware.com/t/dokument-template-durch-plugin-erweitern/92110 "2021-12-28T13:11:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.bayindir](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@m.bayindir](https://forum.shopware.com/u/m.bayindir)\
**Post date:** [28. Dezember 2021 um 13:11 UTC](https://forum.shopware.com/t/dokument-template-durch-plugin-erweitern/92110/1 "2021-12-28T13:11:24Z")

</div>

Hey,

ich versuche aktuell in meinem Plugin das Dokument-Template der Rechnung zu erweitern.

Dafür habe ich folgenden Ansatz gewählt.

Subscriber auf Order

```auto
class DocumentExtension implements SubscriberInterface
{
    /**
     * @var string
     */
    private $pluginDirectory;

    /**
     * @param $pluginDirectory
     */
    public function __construct($pluginDirectory)
    {
        $this->pluginDirectory = $pluginDirectory;
    }
    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PreDispatchSecure_Backend_Order' => 'onOrderPreDispatch'
        ];
    }

    public function onOrderPreDispatch(\Enlight_Event_EventArgs $args)
    {
        /** @var \Shopware_Controllers_Backend_Order $controller */
        $controller = $args->getSubject();

        $view = $controller->View();

        $view->addTemplateDir($this->pluginDirectory . '/Resources/views');
    }
}

```

index.tpl liegt unter Resources/views/documents/

```auto
{extends file='parent:documents/index.tpl'}

{block name="document_index_info_ordercomment"}
    {if $Order._order.customercomment}
        <div style="font-size:11px;color:#333;">
            {s name="DocumentIndexComment"}{/s}
            {$Order._order.customercomment|replace:"€":"&euro;"}
        </div>
    {/if}
    TEST123
{/block}

```

und Service wie folgt registriert

```auto
        <service id="ubi_document_extension.subscriber.templates" class="UbiDocumentExtension\Subscriber\DocumentExtension">
            <argument>%ubi_document_extension.plugin_dir%</argument>
            <tag name="shopware.event_subscriber"/>
        </service>

```

Wenn ich allerdings das Dokument genrieren möchte, seh ich TEST123 nicht auf dem Rechnungsdokument.

Hat jemand eine Idee?

Vielen Dank im Voraus für Eure Mühen

Liebe Grüße

---

<div class="post-metadata">

**Author:** ![m.bayindir](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@m.bayindir](https://forum.shopware.com/u/m.bayindir)\
**Post date:** [31. Dezember 2021 um 13:10 UTC](https://forum.shopware.com/t/dokument-template-durch-plugin-erweitern/92110/2 "2021-12-31T13:10:24Z")

</div>

#push, keiner einen Denkanstoß oder ähnliches?

---

<div class="post-metadata">

**Author:** ![MrAle](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@MrAle](https://forum.shopware.com/u/MrAle)\
**Post date:** [2. Januar 2022 um 09:03 UTC](https://forum.shopware.com/t/dokument-template-durch-plugin-erweitern/92110/3 "2022-01-02T09:03:02Z")

</div>

Hi,

folgender Subscriber dürfte dir helfen:

```auto
'Theme_Inheritance_Template_Directories_Collected' => "onCollectDirectoriesEvent"

```

```auto
	public function onCollectDirectoriesEvent( \Enlight_Event_EventArgs $args )
	{
		// get the current directories
		$directories = $args->getReturn();
 
		// add our own
		array_push(
			$directories,
			$this->pluginDirectory . "/Resources/views"
		);

		return $directories;
	}

```

Grüße
