I created a new module and I try to load a template in an action under indexcontroller. That template loaded properly but the basic/root templates are not loaded. Magento loaded only the template file what I specified in the XML. I explained the steps below what I followed.
- Create a module named ‘Sample’.
- Create a IndexController with a index action.
- Create local.xml file under the dir app/design/frontend/default/default/layout/
- Create sample_page.phtml under the dir app/design/frontend/default/default/template/sample/sample_page.phtml.
IndexController:
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
local.xml:
<layout version="0.1.0">
<default>
</default>
<sample_index_index>
<reference name="root">
<block type="page/html" name="root" output="toHtml" template="sample/sample_page.phtml">
</block>
</reference>
</sample_index_index>
Could anybody find the issue what I done?
The issue here is that you referenced the wrong layout block (“root” in your example). Doing that replace the entire set of blocks for page by the one you specify.
To get all the blocks displayed (included yours), simply reference another layout block than “root“, for example “content“.
You could also want to modify the root layout block for pages of your module, if that is the case, in the default handle, reference the root block and set a different template.
Here is an example :