# Plugin unable to load template

**URL:** <https://forum.shopware.com/t/plugin-unable-to-load-template/45607>\
**Category:** International (English Only)\
**Tags:** themes--design\
**Created:** [5. Mai 2017 um 08:36 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607 "2017-05-05T08:36:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dNovoNiels](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@dNovoNiels](https://forum.shopware.com/u/dNovoNiels)\
**Post date:** [5. Mai 2017 um 08:36 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/1 "2017-05-05T08:36:39Z")

</div>

Hello shopware community,

&nbsp;

When the plugin i made tries to load a custom template on the controller i get the following error message:

> Unable to load template snippet ‚frontend/index/index.tpl|frontend/plugins/seo/index.tpl‘ in engine/Library/Smarty/sysplugins/smarty\_internal\_templatebase.php on line 127

I followed the documentation pretty much to the letter but it somehow doesn’t work at all. And since i’m not using a custom theme for this project i can’t just set injectBeforePlugins = true in a Theme.php file because i’m not using one (as far as i know anyway) and the Bare and Responsive Theme.php file have injectBeforePlugins = true by default.

&nbsp;

For a little more info on how my actual code looks like, my bootstrap file looks like this:

```
/**
     * @inheritdoc
     */
    public static function getSubscribedEvents()
    {
        return [
            'Enlight_Controller_Dispatcher_ControllerPath_Frontend_Event' => 'onGetFrontendController'
        ];
    }

     /**
     * @return string
     */
    public function onGetFrontendController()
    {
        $this->container->get('Template')->addTemplateDir($this->getPath() . '/Resources/views/');

        return $this->getPath() . 'Controllers/Frontend/MyController.php';
    }

```

my template file looks like this:

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

{block name="frontend_index_content_left"}{/block}

{block name="frontend_index_content"}
    
        {foreach $result as $item}
            {* some code *}
        {/foreach}
    
{/block}

```

and my plugin directory structure looks like this:

I’m at a complete loss on how to fix this problem so any help is appreciated 🙂

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [5. Mai 2017 um 08:59 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/2 "2017-05-05T08:59:39Z")

</div>

Hello @dNovoNiels‍,

first of all: Can you provide your MyController.php aswell?

So, basically, you’re overwriting the main template-file in Shopware at the moment:  
_frontend/index/index.tpl_

Nearly your whole Shopware installation should be mostly empty now, since you even replace the main-block&nbsp; **frontend\_index\_content** &nbsp;in your own template.  
Did you just want to provide a custom template for your custom controller? E.g. when you call it like that: [myShop.com/MyController](http://myShop.com/MyController)

Shopware expects a custom&nbsp;template for each frontend controller action by default, placed in the folder equal to the controller-path.  
In that case, you’d have to create a file in the following folder:  
_MyPlugin/Resources/views/frontend/my\_controller/ **index**.tpl_

Just remember: The&nbsp; **index**.tpl&nbsp;must have the same name as the action you’ve called in your controller.  
E.g. indexAction is called =\> You’ll need an **index.tpl**  
fooAction is called =\> You’ll need a **foo.tpl**

Your controller is placed at Frontend/ **MyController** , therefore you need to place your template in the folder&nbsp;frontend/ **my\_controller** , starting from your custom views-directory.

Did this help you a little further or did I just confuse you a little more?&nbsp; ![Foot-in-Mouth](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/bedbc37f276faa6d086ddea9cd70cb0550bbd56e.png "Foot-in-Mouth")

Patrick&nbsp; ![Shopware](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "Shopware")

---

<div class="post-metadata">

**Author:** ![dNovoNiels](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@dNovoNiels](https://forum.shopware.com/u/dNovoNiels)\
**Post date:** [5. Mai 2017 um 09:39 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/3 "2017-05-05T09:39:47Z")

</div>

> [@Patrick Stahl schrieb:](https://forum.shopware.com/profile/1869/Patrick%20Stahl "Patrick%20Stahl")
> 
> Did you just want to provide a custom template for your custom controller? E.g. when you call it like that: [myShop.com/MyController](http://myShop.com/MyController)

&nbsp;yes, that is exactly what i’m trying to achieve. I want to use the same template the homepage has on my controller, and &nbsp;just overwrite the main content block to show what i want it to show. so when i call [myshop.com/MyController](http://myshop.com/MyController) i will see the same layout as the homepage, but diffirent content.

&nbsp;

my MyController.php looks like this:

```
View()->assign('message', $result);
    }
}

```

might aswell add the complete template code while i’m at it 😛

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

{block name="frontend_index_content_left"}{/block}

{block name="frontend_index_content"}
    
        {foreach $result as $item}
            {$item}
        {/foreach}
    
{/block}

```

it’s all pretty simple code so far and as far as i can tell i have it set up in the way that you described it but it still isn’t working 😕

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [5. Mai 2017 um 13:02 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/4 "2017-05-05T13:02:47Z")

</div>

Hey @dNovoNiels‍,

in that case you’ll have to rename the index-folder in your plugin.  
Currently your template is placed in _Resources/views/frontend/ **index** /index.tpl._  
Simply rename it to:  
_Resources/views/frontend/ **my\_controller** /index.tpl_

Then it should work just fine already! 🙂

---

<div class="post-metadata">

**Author:** ![dNovoNiels](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@dNovoNiels](https://forum.shopware.com/u/dNovoNiels)\
**Post date:** [8. Mai 2017 um 08:39 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/5 "2017-05-08T08:39:07Z")

</div>

> [@Patrick Stahl schrieb:](https://forum.shopware.com/profile/1869/Patrick%20Stahl "Patrick%20Stahl")
> 
> in that case you’ll have to rename the index-folder in your plugin.  
> Currently your template is placed in _Resources/views/frontend/ **index** /index.tpl._  
> Simply rename it to:  
> _Resources/views/frontend/ **my\_controller** /index.tpl_
> 
> Then it should work just fine already! 🙂

&nbsp;Hello Patrick,

&nbsp;

Even after renaming the folder, i still get the same error. So unfortunately this solution doesn’t work for me for whatever reason 😕

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [8. Mai 2017 um 09:48 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/6 "2017-05-08T09:48:43Z")

</div>

Hey @dNovoNiels‍,

that should definitely work.

Can you zip & upload your plugin somewhere and send me the link (here or in a private message) ?  
I’d have a quick look into it then, pretty sure I can resolve that issue very fast. 🙂

Patrick&nbsp; ![Shopware](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "Shopware")

---

<div class="post-metadata">

**Author:** ![dNovoNiels](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@dNovoNiels](https://forum.shopware.com/u/dNovoNiels)\
**Post date:** [8. Mai 2017 um 10:12 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/7 "2017-05-08T10:12:45Z")

</div>

> **[File upload and sharing. Large file transfers. Free online cloud storage.](https://files.fm/u/k3bepcrs)**
>
> Visit this link to download: 2017-05-08\_k3bepcrs

I already changed up some of the names of the files and folders but the code is practicly the same as posted above

---

<div class="post-metadata">

**Author:** ![Patrick\_Stahl](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/patrick_stahl/32/7679_2.png) [@Patrick\_Stahl](https://forum.shopware.com/u/Patrick_Stahl)\
**Post date:** [8. Mai 2017 um 11:52 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/8 "2017-05-08T11:52:57Z")

</div>

Hey @dNovoNiels‍,

I got your example to work. 🙂

What did I have to do?  
1st: Your registered event in your DnovoEvents.php was wrong. There was an ‘s’ missing at the end of the string, since your controller is written with a ‘s’ at the end.  
2nd: The path to your controller was missing a slash ( / ) at the beginning in the method&nbsp; **onGetFrontendController**. The path to your custom views directory was correct though and already included a slash.  
3rd: Make sure to only use lower-case folder names in your views-folder. Had to change both “Frontend” and&nbsp;“events” to be lowercase.

After those three adjustments, the plugin worked for me and I could successfully call your custom controller with the proper template.

Do those information help you?

Patrick&nbsp; ![Shopware](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "Shopware")

---

<div class="post-metadata">

**Author:** ![dNovoNiels](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@dNovoNiels](https://forum.shopware.com/u/dNovoNiels)\
**Post date:** [8. Mai 2017 um 12:10 UTC](https://forum.shopware.com/t/plugin-unable-to-load-template/45607/9 "2017-05-08T12:10:52Z")

</div>

> [@Patrick Stahl schrieb:](https://forum.shopware.com/profile/1869/Patrick%20Stahl "Patrick%20Stahl")
> 
> I got your example to work. 🙂
> 
> What did I have to do?  
> 1st: Your registered event in your DnovoEvents.php was wrong. There was an ‚s‘ missing at the end of the string, since your controller is written with a ‚s‘ at the end.  
> 2nd: The path to your controller was missing a slash ( / ) at the beginning in the method&nbsp; **onGetFrontendController**. The path to your custom views directory was correct though and already included a slash.  
> 3rd: Make sure to only use lower-case folder names in your views-folder. Had to change both „Frontend“ and&nbsp;„events“ to be lowercase.
> 
> After those three adjustments, the plugin worked for me and I could successfully call your custom controller with the proper template.
> 
> Do those information help you?
> 
> Patrick&nbsp; ![Shopware](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/1X/86c57fbace799dd4eb1f1b8a2d3bdc1733f0aea1.png "Shopware")

Yes, this worked like a charm 🙂 thank you very much
