Search code examples
phpsmartyshopware

shopware Controller does not get the template


i am trying to create a controller and show something on a view however it ooks like something is wrong. i created a plugin with the following files

SwagStartup/Controllers/Frontend/RoutingDemonstration.php

<?php
class Shopware_Controllers_Frontend_RoutingDemonstration extends Enlight_Controller_Action
{
    public function preDispatch(){
      $this->view->addTemplateDir(_DIR_.'/../../Resources/views');
    }

    public function indexAction()
    {
        //die('Hello world test !');
    }
}

SwagStartup/Resources/views/frontend/routing_demonstration/index.tpl

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

{block name="frontend_index_content"}
    <h1>Hello World</h1>
{/block}

i also have the config.xml,plugin.xml and SwagStartup.php in there right places.

when i uncomment the hello world i will see the text in the browser when i call the controller however when i comment it out then

Oops! An error has occurred!
We have been informed about the problem and try to solve it. Please try again within a short time.

so what could be the issue and am i missing anything? i am using shopware version 5.4.6 and following this did not help either


Solution

  • Just to update incase someone gets the same issue. my problem was here, i think its because i was tired i could not see it.

    $this->view->addTemplateDir(_DIR_.'/../../Resources/views');
    

    that should have been

    $this->view->addTemplateDir(__DIR__.'/../../Resources/views');
    

    it should be __DIR__ and not _DIR_