# Templates im Plugin Theme werden falsch extended

**URL:** https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301
**Category:** Themes & Design
**Created:** [17. Juli 2016 um 16:14 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301 "2016-07-17T16:14:14Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![nexxo](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nexxo](https://forum.shopware.com/u/nexxo)
#### Post date: [17. Juli 2016 um 16:14 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/1 "2016-07-17T16:14:14Z")

</div>

Shopware Version 5.2.2

Ich habe eine Plugin erstellt gemäßt dem neuen Plugin System ([https://developers.shopware.com/developers-guide/plugin-system/](https://developers.shopware.com/developers-guide/plugin-system/))

In diesem Plugin möchte ich nun ein Theme erstellen und das „Responsive“ Theme erweitern.

Die Verzeichnisstruktur ist demnach diese:

![](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/2X/5/52fb9b13364c10700b338681ada44fe80e4b3e61.png)

Hier der Inhalt der Theme.php:

Ich bekomme allerdings immer einen Fehler wenn ich nun ein Parent Template extende (custom/plugins/MyPlugin/Resources/Themes/Frontend/MyTheme/frontend/index/index.tpl):

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

```

> illegal recursive call of „parent:frontend/index/index.tpl“

Anscheinend will er sich immer selber extenden und nicht das Template des Parent Themes

---

<div class="post-metadata">

### Author: ![nexxo](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nexxo](https://forum.shopware.com/u/nexxo)
#### Post date: [18. Juli 2016 um 17:55 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/2 "2016-07-18T17:55:58Z")

</div>

Nach langem debugging habe ich nun selber den Fehler gefunden.

Der “Resources” Ordner MUSS klein geschrieben werden -\> ‘resources’.

Das liegt daran das der Ordner in der Funktion getPluginPath klein geschrieben ist:

engine/Shopware/Components/Theme/PathResolver.php

```
    public function getPluginPath(Plugin $plugin)
    {
        if ($plugin->isLegacyPlugin()) {
            return $this->pluginDirectories[$plugin->getSource()] . $plugin->getNamespace() . DIRECTORY_SEPARATOR . $plugin->getName();
        }

        return $this->rootDir . '/custom/plugins/' . $plugin->getName() . '/resources';
    }

```

Wenn der Ordner nun wie in meinem Fall groß geschrieben wird, kann er das Template nicht richtig zuordnen:

```
    protected function buildFilepath(Smarty_Template_Source $source, Smarty_Internal_Template $_template = null)
    {
        $this->index++;
        $file = $source->name;
        $hit = false;

        foreach ($source->smarty->getTemplateDir() as $_directory) {
            $_filePath = realpath($_directory . $file);
            if ($this->fileExists($source, $_filePath)) {
                if ($hit) {
                    return $_filePath;
                }
                if ($_template->parent->source->filepath == $_filePath) {
                    $hit = true;
                }
            }
        }

        return parent::buildFilepath($source, $_template);
    }

```

\_template-\\>parent-\\>source-\\>filepath == \_filePath trifft da nie zu und er gibt den falschen Pfad zurück.

&nbsp;

Nun die Frage, ist das so gewollt das “resources” immer klein geschrieben wird? In der Dokumentation ist es groß [https://developers.shopware.com/developers-guide/plugin-system/#container-configuration](https://developers.shopware.com/developers-guide/plugin-system/#container-configuration)

---

<div class="post-metadata">

### Author: ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)
#### Post date: [18. Juli 2016 um 19:22 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/3 "2016-07-18T19:22:33Z")

</div>

Funktioniert das config.xml noch, wenn Du resources klein schreibst?

---

<div class="post-metadata">

### Author: ![nexxo](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nexxo](https://forum.shopware.com/u/nexxo)
#### Post date: [18. Juli 2016 um 19:50 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/4 "2016-07-18T19:50:30Z")

</div>

Ich binde momentan nur eine .yml Datei ein, das funktioniert zumindest in der Entwicklungsumgebung obwohl der Pfad jetzt nicht mehr stimmt:

```
$loader->load($this->getPath().'/Resources/services.yml');

```

Ich kann mir aber vorstellen das er die .xml und andere Ressourcen jetzt nicht mehr findet. Da es sonst überall groß geschrieben wird, gehe ich mal davon aus dass das ein Bug ist und in der getPluginPath Funktion auch groß geschrieben werden sollte.

---

<div class="post-metadata">

### Author: ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)
#### Post date: [20. Juli 2016 um 11:03 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/5 "2016-07-20T11:03:08Z")

</div>

Also ich habe das mal bei einem Plugin ausprobiert. Wenn ich “resources” statt “Resources” verwende, wars das mit der Installationsroutine. Funktioniert nicht mehr…

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Konnte ich Dir **helfen**? Dann freue ich mich über ein **Danke** 😉

---

<div class="post-metadata">

### Author: ![nexxo](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nexxo](https://forum.shopware.com/u/nexxo)
#### Post date: [20. Juli 2016 um 17:23 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/6 "2016-07-20T17:23:10Z")

</div>

Dann scheint das tatsächlich ein Bug zu sein. Liest das hier jemand von Shopware oder soll ich das besser wo anders melden?

Ich denke auch dass das ‚/resources‘ da gar nicht hingehört und die Funktion zu dem Hauptordner des Plugins führen soll.

```
return $this->rootDir . '/custom/plugins/' . $plugin->getName() . '/resources';

```

&nbsp;

---

<div class="post-metadata">

### Author: ![Synonymous](https://avatars.discourse-cdn.com/v4/letter/s/57b2e6/32.png) [@Synonymous](https://forum.shopware.com/u/Synonymous)
#### Post date: [21. Juli 2016 um 07:46 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/7 "2016-07-21T07:46:07Z")

</div>

Am besten ein Ticket im Bugtracker anlegen…

---

<div class="post-metadata">

### Author: ![Daniel\_Bottner](https://avatars.discourse-cdn.com/v4/letter/d/a5b964/32.png) [@Daniel\_Bottner](https://forum.shopware.com/u/Daniel_Bottner)
#### Post date: [7. Dezember 2016 um 13:15 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/8 "2016-12-07T13:15:51Z")

</div>

Weiß jemand ob dies gepatcht wurde?

---

<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: [7. Dezember 2016 um 14:38 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/9 "2016-12-07T14:38:11Z")

</div>

Hallo,

ich hab dafür mal ein Ticket angelegt und einen PR gestellt. Sollte in der nächsten Patch Version behoben werden.

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: ![nexxo](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nexxo](https://forum.shopware.com/u/nexxo)
#### Post date: [7. Dezember 2016 um 15:08 UTC](https://forum.shopware.com/t/templates-im-plugin-theme-werden-falsch-extended/38301/10 "2016-12-07T15:08:54Z")

</div>

In der 5.3 Branch wurde es gefixt [SW-15736 - Fix theme path resolver for new plugins. · shopware/shopware@1227379 · GitHub](https://github.com/shopware/shopware/commit/1227379e872497683e14dc86fb493fc22b02ed4a)

> **[Shopware Issuetracker](https://issues.shopware.com/issues/SW-15736)**

Ich habe es temporär selber so gelöst:

```
$container->addCompilerPass(new PathResolverCompilerPass());

// PathResolverCompilerPass.php
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;

class PathResolverCompilerPass implements CompilerPassInterface
{
    public function process(ContainerBuilder $container)
    {
        if (!$container->hasDefinition('theme_path_resolver')) {
            return;
        }

        $definition = $container->getDefinition('theme_path_resolver');
        $definition->setClass(PathResolver::class);
        $definition->addMethodCall('setRootDir', array($container->getParameter('kernel.root_dir')));
        $definition->addMethodCall('setPluginDirectories', array($container->getParameter('shopware.plugin_directories')));
    }
}

// PathResolver.php
use Shopware\Components\Theme\PathResolver AS ShopwarePathResolver;
use Shopware\Models\Plugin\Plugin;

class PathResolver extends ShopwarePathResolver
{
    /**
     * @var string
     */
    private $rootDir;

    /**
     * @var array
     */
    private $pluginDirectories;

    /**
     * @param string $rootDir
     */
    public function setRootDir($rootDir){
        $this->rootDir = $rootDir;
    }

    /**
     * @param array $pluginDirectories
     */
    public function setPluginDirectories(array $pluginDirectories){
        $this->pluginDirectories = $pluginDirectories;
    }

    /**
     * Helper function to build the path to the passed plugin.
     *
     * @param Plugin $plugin
     * @return string
     */
    public function getPluginPath(Plugin $plugin)
    {
        if ($plugin->isLegacyPlugin()) {
            return $this->pluginDirectories[$plugin->getSource()] . $plugin->getNamespace() . DIRECTORY_SEPARATOR . $plugin->getName();
        }

        return $this->rootDir . '/custom/plugins/' . $plugin->getName() . '/Resources';
    }
}

```

&nbsp;
