# Failing to register template

**URL:** https://forum.shopware.com/t/failing-to-register-template/55092
**Category:** International (English Only)
**Tags:** programming
**Created:** [11. September 2018 um 05:54 UTC](https://forum.shopware.com/t/failing-to-register-template/55092 "2018-09-11T05:54:27Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![psky](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@psky](https://forum.shopware.com/u/psky)
#### Post date: [11. September 2018 um 05:54 UTC](https://forum.shopware.com/t/failing-to-register-template/55092/1 "2018-09-11T05:54:27Z")

</div>

```
'onPreDispatchTemplateRegistration'
    ];
  }
  public function onPreDispatchTemplateRegistration(\Enlight_Event_EventArgs $args){
    /** @var |Shopware_Controllers_Frontend_RoutingDemonstration $subject*/
    $controller = $args->getSubject();
    //register template directory
    $controller->View()->addTemplateDir(_DIR_.'/Resources/views');
    $controller->templateManager->addTemplateDir($this->pluginDirectory . '/Resources/views');
    /*$request = $controller->Request();
    $view = $controller->View();
    $response = $controller->Response();*/
  }

}

```

custom/plugins/SwagStartup/SwagStartup.php

i have the above code in my SwagStartup.php and i have the templates in the location below

custom/plugins/SwagStartup/Resources/views/frontend/routing\_demonstration/index.tpl

however the template cannot be registered and gives the following error.

```
Fatal error: Uncaught SmartyException: Unable to load template snippet 'frontend/routing_demonstration/index.tpl|frontend/plugins/seo/index.tpl' in /shopware/engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php:127 Stack trace: #0 /shopware/engine/Library/Enlight/View/Default.php(300): Smarty_Internal_TemplateBase->fetch() #1 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(216): Enlight_View_Default->render(Object(Enlight_Template_Default)) #2 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(242): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->renderTemplate(Object(Enlight_Template_Default)) #3 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(136): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->render() #4 /shopware/engine/Library/Enlight/Event/Handler/Default.php(91): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->onPostDispatch(Object(Enlight_Controller_ActionEventArgs)) #5 /shopware/engine/Library/Enlight in /shopware/engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php on line 127

```

What am i missing and how can i solve this. i was following the tutorial on [udemy](https://www.udemy.com/developer-training-basic-english/learn/v4/t/lecture/9057622?start=30).

---

<div class="post-metadata">

### Author: ![shyim](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/shyim/32/7681_2.png) [@shyim](https://forum.shopware.com/u/shyim)
#### Post date: [11. September 2018 um 06:28 UTC](https://forum.shopware.com/t/failing-to-register-template/55092/2 "2018-09-11T06:28:34Z")

</div>

The line&nbsp;return parent::getSubscribedEvents(); is too much. Your event is never considered.

---

<div class="post-metadata">

### Author: ![psky](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@psky](https://forum.shopware.com/u/psky)
#### Post date: [11. September 2018 um 06:57 UTC](https://forum.shopware.com/t/failing-to-register-template/55092/3 "2018-09-11T06:57:46Z")

</div>

```
namespace SwagStartup;

use Shopware\Components\Plugin;

class SwagStartup extends Plugin{
  public static function getSubscribedEvents(){
    return[
      'Enlight_Controller_Action_preDispatch_Frontend_RoutingDemonstration'=>'onPreDispatchTemplateRegistration'
    ];
  }
  public function onPreDispatchTemplateRegistration(\Enlight_Event_EventArgs $args){
    /** @var |Shopware_Controllers_Frontend_RoutingDemonstration $subject*/
    $controller = $args->getSubject();
    //register template directory
    $controller->View()->addTemplateDir(_DIR_.'/Resources/views');
  }

}

```

Thank you for the response. Even when i remove that line i still the the following error message

```
Fatal error: Uncaught SmartyException: Unable to load template snippet 'frontend/routing_demonstration/index.tpl|frontend/plugins/seo/index.tpl' in /shopware/engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php:127 Stack trace: #0 /shopware/engine/Library/Enlight/View/Default.php(300): Smarty_Internal_TemplateBase->fetch() #1 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(216): Enlight_View_Default->render(Object(Enlight_Template_Default)) #2 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(242): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->renderTemplate(Object(Enlight_Template_Default)) #3 /shopware/engine/Library/Enlight/Controller/Plugins/ViewRenderer/Bootstrap.php(136): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->render() #4 /shopware/engine/Library/Enlight/Event/Handler/Default.php(91): Enlight_Controller_Plugins_ViewRenderer_Bootstrap->onPostDispatch(Object(Enlight_Controller_ActionEventArgs)) #5 /shopware/engine/Library/Enlight in /shopware/engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php on line 127

```

&nbsp;

---

<div class="post-metadata">

### Author: ![psky](https://avatars.discourse-cdn.com/v4/letter/p/3be4f8/32.png) [@psky](https://forum.shopware.com/u/psky)
#### Post date: [12. September 2018 um 05:34 UTC](https://forum.shopware.com/t/failing-to-register-template/55092/4 "2018-09-12T05:34:43Z")

</div>

Finally gotten the issue and solved it

I had to change this line from&nbsp;

```
$controller->View()->addTemplateDir(_DIR_.'/Resources/views');

```

to  
&nbsp;

```
$controller->View()->addTemplateDir( __DIR__. '/Resources/views/');

```

&nbsp;

I am not sure why this differs from what the video has and why his works and mine doesnt.
