Plugin unable to load template part 2

Hello Shopware community,

 

This is more or less a continuation of my previous post here. Same problem, slightly diffirent setting.

Again, i am trying to load a custom template on a custom controller but i am getting the following error.

Unable to load template snippet ‚frontend/event_detail/index.tpl|frontend/plugins/seo/index.tpl‘ in engine/Library/Smarty/sysplugins/smarty_internal_templatebase.php on line 127

The difference with this problem compared to my previous one, is that this time i am not subscribing to a event to load the controller, but i am redirecting the user from one controller to another controller through an html a tag.

I am using the following code in the first controllers template, this is where the redirect happens:

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

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

{block name="frontend_index_content"}
    
        {foreach $messages as $message}
            {$message}
            View
        {/foreach}
    
{/block}

I am getting redirected to the correct page but the template isn’t loading and the error stated above is generated.

My directory structure looks like this:

The code inside my EventDetail.php file is a simple indexAction() that assigns an array to the template.

As far as i can tell i have the correct directory structure and correct names for my files. Here is a download link to my plugin.

Any help would be greatly appreciated :slight_smile:

Hey @dNovoNiels‍,

I downloaded your example plugin and only got a single issue:
The controller was not yet registered in your DnovoEvents.php , so you have to add code like that:

public static function getSubscribedEvents()
{
    return [
        ....
        'Enlight_Controller_Dispatcher_ControllerPath_Frontend_EventDetail' => 'onGetFrontendDetailsController'
    ];
}

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

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

After I added the new controller, I could successfully load the page myShop.de/EventDetail - your template was loaded properly then.
No idea why you’re facing the “Template could not be loaded” error, since your controller wasn’t registered yet.

Does this information help you?

Patrick  Shopware

yep, this awnsers my question Smile thanks again for the help

somehow i thought i wouldn’t have to subsribe to an event to get this to work Undecided

You need to register each custom controller to Shopware.

E.g. you have 4 custom controllers, then you’ll also need four additional events for Shopware to know your custom controllers. :slight_smile:

good to know that for future projects :slight_smile: