# Inject Custom CSS Datei für Backend Plugin im 5.2 System

**URL:** <https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290>\
**Category:** Programmierung\
**Created:** [18. April 2017 um 13:36 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290 "2017-04-18T13:36:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)\
**Post date:** [18. April 2017 um 13:36 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/1 "2017-04-18T13:36:35Z")

</div>

Ich habe schon so viele Kombinationen versucht und beispiele aus anderen Plugins versucht abzuleuten, aber ich schaffe es nicht, dass im Backend meine custom CSS-Datei mitgeladen wird.

Hier ist der letzte Stand den ich habe:

```
// Datei: /Resources/Views/backend/index/header.tpl

{extends file="parent:backend/index/header.tpl"}

{block name="backend/base/header/css" append}
    
{/block}

// Datei .php

    public static function getSubscribedEvents()
    {
        return [            
            'Enlight_Controller_Action_PostDispatchSecure_Backend_Index'
            => 'onPostDispatchSecureBackendIndex'
        ];
    }

    public function onPostDispatchSecureBackendIndex(\Enlight_Event_EventArgs $args) {
        $this->container->get('Template')->addTemplateDir(
            $this->getPath() . '/Resources/Views/'
        );
    }

```

&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:** [18. April 2017 um 14:32 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/2 "2017-04-18T14:32:06Z")

</div>

Hallo langnickel,

die Template Erweiterung funktioniert für das Backend ein bisschen anders als im Frontend.  
Probiere mal folgenden Code in deiner Event Callback Methode:

```
public function onPostDispatchSecureBackendIndex(\Enlight_Event_EventArgs $args) {
    $this->container->get('Template')->addTemplateDir(
        $this->getPath() . '/Resources/Views/'
    );
    $view->extendsTemplate('../Resources/Views/backend/index/header.tpl');

}

```

Deine tpl Datei musst du dann auch noch ein bisschen ändern. Der „extends“ Befehl muss raus.&nbsp;

```
{block name="backend/base/header/css"}
    {$smarty.block.parent}
    
{/block}

```

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:** ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)\
**Post date:** [18. April 2017 um 14:45 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/3 "2017-04-18T14:45:22Z")

</div>

Danke, das hatte ich ebenfalls schon probiert, stoß dann aber auf folgende Expcetion:

```
Fatal error: Uncaught SmartyException: Unable to load template snippet 'backend/index/index.tpl|../Resources/Views/backend/index/header.tpl' in 

```

und wenn ich den relativen Pfad rausnehme un ändere in  
&nbsp;

```
$args->getSubject()->View()->extendsTemplate('backend/index/header.tpl');

```

kommt zwar keine Exception, aber der tag is trotzdem nicht da 😕

Übringens: kleiner Fehler bei dir ?:

statt $view eventuell&nbsp;

```
 $args-\>getSubject()-\>View()-\>

```

benutzen ?

---

<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:** [18. April 2017 um 14:55 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/4 "2017-04-18T14:55:18Z")

</div>

Hallo langnickel,

ja genau.&nbsp;Hatte das aus einem Plugin kopiert und da ist in $view das gespeichert, was du geschrieben hattest&nbsp; ![Wink](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/wink.png "Wink")

Zu dem Fehler: Versuche mal durch einen weiteren Unterordner einen anderen „Namespace“ für deine Template Datei einzuführen. Also so was wie: „/Resources/Views/backend/meinPlugin/index/header.tpl“  
Zusätzlich solltest du das mit den Punkten überprüfen: Zwei Punkte „…“ bedeutet, dass Shopware beim laden des Templates erstmal einen Ordner hoch geht. Je nach dem, wo du dieses Event abfängst, musst das gesetzt werden, oder aber auch nicht.

Grundsätzlich bitte nicht einfach alles blind kopieren&nbsp; ![Smile](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/smile.png "Smile")&nbsp;Ich kenne dein Plugin und dessen Aufbau nicht, kann also meine Aussagen nicht zu 100% verifizieren und testen&nbsp; ![Wink](https://forum.shopware.com/plugins/CKEditor/plugins/smiley/images/wink.png "Wink")

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:** ![langnickel](https://avatars.discourse-cdn.com/v4/letter/l/3ec8ea/32.png) [@langnickel](https://forum.shopware.com/u/langnickel)\
**Post date:** [18. April 2017 um 15:02 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/5 "2017-04-18T15:02:50Z")

</div>

Danke, naja blind kopiert hab ichs nicht, sonst hätt ich das mit der $view nicht erwähnt :), und dass mit den relativen Pfaden das war semi-blind weil ich dachte, das gehört dazu. Das mit dem namespace hat geklappt, daran lags. danke 🙂

Für die Nachwelt: So kann man eine custom CSS-.Datei im 5.2 System dem backend hinzufügen:

```
    // Plugin PHP-Datei:

    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Action_PostDispatchSecure_Backend_Index'
            => 'onPostDispatchSecureBackendIndex'
        ];
    }

    public function onPostDispatchSecureBackendIndex(\Enlight_Event_EventArgs $args) {
        $this->container->get('Template')->addTemplateDir(
            $this->getPath() . '/Resources/Views/'
        );
        $args->getSubject()->View()->extendsTemplate('backend//index/header.tpl');
    }

    // ../Resources/Views/backend//index/header.tpl:
    {block name="backend/base/header/css"}
        {$smarty.block.parent}
        
    {/block}

```

Hoffe es hilft jemand 🙂 Danke für die Hilfe

---

<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:** [18. April 2017 um 15:05 UTC](https://forum.shopware.com/t/inject-custom-css-datei-fur-backend-plugin-im-5-2-system/45290/6 "2017-04-18T15:05:21Z")

</div>

super&nbsp; ![Thumb-Up](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/7fcda44f782696668a3d093569d15e88105769e1.png "Thumb-Up") ![Smile](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bac5f5766b6a20565a8fb995345b4e41d24daac0.png "Smile")
