dNovoNielsdNovoNiels MemberComments: 8 Received thanks: 0 Member since: May 2017 edited May 2017

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"}
    <section>
        {foreach $messages as $message}
            <p>{$message}</p>
            <a href="{url controller='EventDetail' action='index'}"><button>View</button></a>
        {/foreach}
    </section>
{/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:

Plugin directory structure

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 :)

1 Answer

  • Patrick StahlPatrick Stahl ModeratorComments: 538 Received thanks: 238 edited May 2017 Member since: August 2011

    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

    Quote
    Accepted Answer
  • Accepted Answer

Answers

  • Patrick StahlPatrick Stahl ModeratorComments: 538 Received thanks: 238 edited May 2017 Member since: August 2011

    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

    Quote
    Accepted Answer
  • dNovoNielsdNovoNiels MemberComments: 8 Received thanks: 0 Member since: May 2017

    yep, this awnsers my questionSmile thanks again for the help

    somehow i thought i wouldn't have to subsribe to an event to get this to workUndecided

  • Patrick StahlPatrick Stahl ModeratorComments: 538 Received thanks: 238 Member since: August 2011

    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. :-)

  • dNovoNielsdNovoNiels MemberComments: 8 Received thanks: 0 Member since: May 2017

    good to know that for future projects :)

Sign In or Register to comment.