1

How to override block named "content" from page.xml? Am I doing it right? Cause below code not return expected value.

\app\code\local\Trening\NewModule\controllers\IndexController.php:

class Trening_NewModule_IndexController extends Mage_Core_Controller_Front_Action{
    public function sayHelloAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }

\app\code\local\Trening\NewModule\etc\config.xml:

<config>
    <frontend>
        <routers>
            <trening_newmodule>
                <use>standard</use> 
                <args>
                    <module>Trening_NewModule</module>
                    <frontName>trening</frontName> 
                </args>
            </trening_newmodule>
        </routers>
        <layout>
            <updates>
                <newmodule>
                    <file>trening.xml</file>
                </newmodule>
            </updates>
        </layout>
    </frontend>
</config>

\app\design\frontend\default\trening\layout\trening.xml:

<layout>
    <trening_newmodule_index_sayhello>
        <reference name="content">
                <block type="newmodule/product" name="newmodule" template="trening/myproducts.phtml" />
        </reference>
    </trening_newmodule_index_sayhello>
</layout>

\app\design\frontend\default\trening\template\trening\myproducts.phtml:

<h1>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</h1>
<?php echo $this->getProducts(); ?>

\app\code\local\Trening\NewModule\Block\Product.php:

class Trening_NewModule_Block_Product extends Mage_Core_Block_Template
{
    public function getProducts()
    {
        return "it works!;";
    }
}

enter image description here enter image description here

  • dashboard/admin/configuration/design Package_Name: rwd, Themes :blank

2 Answers 2

1

Make sure you have "trening" theme set as default, otherwise keep FE files in base/default.

0

You need to replace code in ,

app\design\frontend\default\trening\layout\trening.xml:

<layout>
    <trening_newmodule_index_sayhello>
        <reference name="content">
                <block type="newmodule/product" name="newmodule" template="trening/myproducts.phtml" />
        </reference>
    </trening_newmodule_index_sayhello>
</layout>

With

<layout>
    <trening_index_sayhello>
        <reference name="content">
                <block type="newmodule/product" name="newmodule" template="trening/myproducts.phtml" />
        </reference>
    </trening_index_sayhello>
</layout>

And change your controller,

app\code\local\Trening\NewModule\controllers\IndexController.php

class Trening_NewModule_IndexController extends Mage_Core_Controller_Front_Action{
    public function sayhelloAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}
5
  • removed newmodule and lower case controller action name. Still the same unfortunately. Jan 18, 2017 at 3:26
  • try with caching and then check. verify code one's. Jan 18, 2017 at 3:27
  • try/catching $this->loadLayout() in controller? Jan 18, 2017 at 3:35
  • Magento caching from admin or remove cache folder from Magento Root/var/cache. Jan 18, 2017 at 4:27
  • im in no-cache mode, all time Jan 18, 2017 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.