Home > OS >  Shopware 5 Controller cant find templates
Shopware 5 Controller cant find templates

Time:11-24

I am trying to call a template using the controller but I cant get the template to show. I registered the Controller and the subscriber inside of the serivces.xml. The name of the folder that holds the template is the same name as the Controller lorem_questions. I cant find the problem. Here are some sniptes of my code.

Subscriber:

        public static function getSubscribedEvents()
        {
            return [
                'Enlight_Controller_Action_PreDispatch' => 'addTemplateDir',
                ];
        }

        public function addTemplateDir()
        {
            $this->templateManager->addTemplateDir($this->pluginDirectory . '/Resources/views/');

        }

Controller:

class LoremQuestions extends Enlight_Controller_Action
{

    public function indexAction()
    {

    }

    public function loremQuestionsPrinterAction()
    {

       die($this->View()->assign("name", 2));
    }

templates:

{extends file="parent:frontend/index/index.tpl"}
{block name="frontend_index_navigation_categories_top_include"}
    <h1>yhfsajf</h1>
    <h1>fsakfsa</h1>
    <h1>fsakfsa</h1>
{/block}

or:

{extends file="parent:frontend/index/index.tpl"}
{block name="frontend_detail_tabs_navigation_inner" append}
    <a href="#"  title="Tab" data-tabName="tab">Fragen</a>
{/block}

{block name="frontend_detail_tabs_content_inner" append}
    {debug}
    <div >
        <div >
            <a href="#" >Fragen</a>
        </div>

        <div >
            <a href="#" >um die Fragen zu sehen hier Klicken</a>
        </div>

        <div >
            <div >
                <h1>{$name}</h1>
            </div>
        </div>
    </div>
{/block}

services:

        <!--  Subscriber    -->
        <service id="lorem_questions.subscriber.frontend_subscriber"
                 >
            <argument>%lorem_questions.plugin_dir%</argument>
            <argument id="template" type="service"/>
            <tag name="shopware.event_subscriber"/>
        </service>
        <!--  Controller    -->
        <service id="LoremQuestions\Controller\Frontend\LoremQuestions">
            <tag name="shopware.controller" module="frontend" controller="LoremQuestions"/>
        </service>

CodePudding user response:

I fixed the problem by changing and renaming the folder that contained the Templates and the Controller.php it self so instead of havingLoremQuestions as a controller I deleted it and created another Controller and named it Questions after that I deleted the folder that hold the Templates and made a new one so instead lorem_questionswith the name of questions and re-registered the Controller inside of the services.xml and it works now. I am getting the values inside of the Templates can someone please Explain to me why it worked after changing the names?

serives.xml now Looks like this :

        <service id="LoremQuestions\Controller\Frontend\Questions">
            <tag name="shopware.controller" module="frontend" controller="Questions"/>
        </service>
  • Related