Failing to register template

'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.

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

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

 

Finally gotten the issue and solved it

I had to change this line from 

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

to
 

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

 

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