Magento Unable to load my custom layout through controller The Next CEO of Stack...
How to count occurrences of text in a file?
Novel about a guy who is possessed by the divine essence and the world ends?
Received an invoice from my ex-employer billing me for training; how to handle?
What can we do to stop prior company from asking us questions?
How did the Bene Gesserit know how to make a Kwisatz Haderach?
How did people program for Consoles with multiple CPUs?
What exact does MIB represent in SNMP? How is it different from OID?
MessageLevel in QGIS3
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Sending manuscript to multiple publishers
Elegant way to replace substring in a regex with optional groups in Python?
Which kind of appliances can one connect to electric sockets located in an airplane's toilet?
Preparing Indesign booklet with .psd graphics for print
Rotate a column
In the bitcoin scripting language, how can I access other outputs of the transaction? Or how else can I limit how the coins may be spent?
Can I equip Skullclamp on a creature I am sacrificing?
If the heap is initialized for security, then why is the stack uninitialized?
Return the Closest Prime Number
Unreliable Magic - Is it worth it?
What happened in Rome, when the western empire "fell"?
Is it my responsibility to learn a new technology in my own time my employer wants to implement?
Why does standard notation not preserve intervals (visually)
Is it professional to write unrelated content in an almost-empty email?
What was the first Unix version to run on a microcomputer?
Magento Unable to load my custom layout through controller
The Next CEO of Stack OverflowIndexController: loadLayout() not working inside postAction() (Helper_Data not found)magento can't load block via controllerCat banner call results in fatal errorNot display Front endrewrite block not workingCustom module does not display in pageCustom phtml not getting called from the Block magentoCustom table data not shown in tempalte file Magento 2How to do work with custom module Admin PanelMagento 1.9 add layout and template to custom module in admin
I have created a module with controller and model. But I am now trying to load a custom view where I can stuff all my PHP,css,js code into that PHTML file.
Here is my Block of Code
appcodelocalSoumenTestmodulecontrollersIndexController.php
IndexController file
public function indexAction()
{
echo "This is default";
}
public function sayHelloAction()
{
Mage::log('im in Controller');
$this->loadLayout();
$this->renderLayout();
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
Config file
appcodelocalSoumenTestmoduleetcconfig.xml
<config>
<frontend>
<routers>
<Soumen_Testmodule>
<use>standard</use>
<args>
<module>Soumen_Testmodule</module>
<frontName>testmodule</frontName>
</args>
</Soumen_Testmodule>
</routers>
<layout>
<updates>
<testmodule>
<file>testmodule.xml</file>
</testmodule>
</updates>
</layout>
</frontend>
</config>
appdesignfrontendbasedefaultlayouttestmodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<testmodule_index_index>
<reference name="content">
<block type="testmodule/test" name="test" template="testmodule/test.phtml" />
</reference>
</testmodule_index_index>
</layout>`
appcodelocalSoumenTestmoduleBlockTest.php
class Soumen_Testmodule_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
appdesignfrontendbasedefaulttemplatetestmoduletest.phtml
<?php echo $this->getContent();?>
Now when I call http://magento/testmodule... Then it displays the dufault page,
but should show Hello World . Can Someone help me out , that what wrong I am doing
magento-1.9 blocks
add a comment |
I have created a module with controller and model. But I am now trying to load a custom view where I can stuff all my PHP,css,js code into that PHTML file.
Here is my Block of Code
appcodelocalSoumenTestmodulecontrollersIndexController.php
IndexController file
public function indexAction()
{
echo "This is default";
}
public function sayHelloAction()
{
Mage::log('im in Controller');
$this->loadLayout();
$this->renderLayout();
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
Config file
appcodelocalSoumenTestmoduleetcconfig.xml
<config>
<frontend>
<routers>
<Soumen_Testmodule>
<use>standard</use>
<args>
<module>Soumen_Testmodule</module>
<frontName>testmodule</frontName>
</args>
</Soumen_Testmodule>
</routers>
<layout>
<updates>
<testmodule>
<file>testmodule.xml</file>
</testmodule>
</updates>
</layout>
</frontend>
</config>
appdesignfrontendbasedefaultlayouttestmodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<testmodule_index_index>
<reference name="content">
<block type="testmodule/test" name="test" template="testmodule/test.phtml" />
</reference>
</testmodule_index_index>
</layout>`
appcodelocalSoumenTestmoduleBlockTest.php
class Soumen_Testmodule_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
appdesignfrontendbasedefaulttemplatetestmoduletest.phtml
<?php echo $this->getContent();?>
Now when I call http://magento/testmodule... Then it displays the dufault page,
but should show Hello World . Can Someone help me out , that what wrong I am doing
magento-1.9 blocks
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
add yourtestmodule.xml
from layout folder and block code
– sandip
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19
add a comment |
I have created a module with controller and model. But I am now trying to load a custom view where I can stuff all my PHP,css,js code into that PHTML file.
Here is my Block of Code
appcodelocalSoumenTestmodulecontrollersIndexController.php
IndexController file
public function indexAction()
{
echo "This is default";
}
public function sayHelloAction()
{
Mage::log('im in Controller');
$this->loadLayout();
$this->renderLayout();
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
Config file
appcodelocalSoumenTestmoduleetcconfig.xml
<config>
<frontend>
<routers>
<Soumen_Testmodule>
<use>standard</use>
<args>
<module>Soumen_Testmodule</module>
<frontName>testmodule</frontName>
</args>
</Soumen_Testmodule>
</routers>
<layout>
<updates>
<testmodule>
<file>testmodule.xml</file>
</testmodule>
</updates>
</layout>
</frontend>
</config>
appdesignfrontendbasedefaultlayouttestmodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<testmodule_index_index>
<reference name="content">
<block type="testmodule/test" name="test" template="testmodule/test.phtml" />
</reference>
</testmodule_index_index>
</layout>`
appcodelocalSoumenTestmoduleBlockTest.php
class Soumen_Testmodule_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
appdesignfrontendbasedefaulttemplatetestmoduletest.phtml
<?php echo $this->getContent();?>
Now when I call http://magento/testmodule... Then it displays the dufault page,
but should show Hello World . Can Someone help me out , that what wrong I am doing
magento-1.9 blocks
I have created a module with controller and model. But I am now trying to load a custom view where I can stuff all my PHP,css,js code into that PHTML file.
Here is my Block of Code
appcodelocalSoumenTestmodulecontrollersIndexController.php
IndexController file
public function indexAction()
{
echo "This is default";
}
public function sayHelloAction()
{
Mage::log('im in Controller');
$this->loadLayout();
$this->renderLayout();
Zend_Debug::dump($this->getLayout()->getUpdate()->getHandles());
}
Config file
appcodelocalSoumenTestmoduleetcconfig.xml
<config>
<frontend>
<routers>
<Soumen_Testmodule>
<use>standard</use>
<args>
<module>Soumen_Testmodule</module>
<frontName>testmodule</frontName>
</args>
</Soumen_Testmodule>
</routers>
<layout>
<updates>
<testmodule>
<file>testmodule.xml</file>
</testmodule>
</updates>
</layout>
</frontend>
</config>
appdesignfrontendbasedefaultlayouttestmodule.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<testmodule_index_index>
<reference name="content">
<block type="testmodule/test" name="test" template="testmodule/test.phtml" />
</reference>
</testmodule_index_index>
</layout>`
appcodelocalSoumenTestmoduleBlockTest.php
class Soumen_Testmodule_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
appdesignfrontendbasedefaulttemplatetestmoduletest.phtml
<?php echo $this->getContent();?>
Now when I call http://magento/testmodule... Then it displays the dufault page,
but should show Hello World . Can Someone help me out , that what wrong I am doing
magento-1.9 blocks
magento-1.9 blocks
edited 28 mins ago
Teja Bhagavan Kollepara
3,01241949
3,01241949
asked Jan 11 '17 at 16:22
Soumen Kumar SahaSoumen Kumar Saha
13
13
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
add yourtestmodule.xml
from layout folder and block code
– sandip
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19
add a comment |
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
add yourtestmodule.xml
from layout folder and block code
– sandip
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
add your
testmodule.xml
from layout folder and block code– sandip
Jan 11 '17 at 16:27
add your
testmodule.xml
from layout folder and block code– sandip
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19
add a comment |
2 Answers
2
active
oldest
votes
In your testmodule.xml
file use this
<testmodule_index_sayHello>
<reference name="content">
<block type="modulename/block" name="testmodule" template="newpage/content.phtml"/>
</reference>
</testmodule_index_sayHello>
If you don't have block of your module then you can use core/template
as block type
add a comment |
There are few changes to make to the existing config.xml file. Since now we are using layouts, we will create our own layout file for our module. Lets name our module’s layout file as test.xml. We will place it in our theme/layout folder.
<?xml version="1.0"?>
<config>
<modules>
<Excellence_Test>
<version>0.1.0</version>
</Excellence_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Excellence_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout> <!-- New Section Added -->
<updates>
<test>
<file>test.xml</file> <!-- This is name of the layout file for this module -->
</test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Excellence_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Excellence_Test_Helper</class>
</test>
</helpers>
</global>
</config>
Now create the test.xml file in your theme layout folder. Like in my case its app/design/frontend/default/default/layout/test.xml or if you have create your own theme, put the layout file there. Here are the contents of the file.
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/test" name="test" template="test/test.phtml" />
</reference>
</test_index_index>
</layout>
The explanation of this layout file is given previously here. So the block we used is “test/test” which equal class Excellence_Test_Block_Test and phtml file used is test/test.phtml
So we will create a phtml file in location app/design/frontend/default/default/templates/test/test.phtml
<?php
echo $this->getContent();
?>
In the file, we are calling a function getContent(); this function is to be declared in the block Test.php block file. As we have seen previous, the $this variable here is actually an object of our block class, which we define as ‘type’ in our layout.xml. Just to confirm you write below code in your phtml file.
<?php echo get_class($this); ?>
The output should be Excellence_Test_Block_Test.
Now create the file Test.php at location app/code/local/Excellence/Test/Block/Test.php
<?php
class Excellence_Test_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
Now, to call all these layouts we need to make some changes in the IndexController.php
<?php
class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(); //This function read all layout files and loads them in memory
$this->renderLayout(); //This function processes and displays all layout phtml and php files.
}
}
Open the url www.your-magento.com/test/ again and it will again print ‘helloword’.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154293%2fmagento-unable-to-load-my-custom-layout-through-controller%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your testmodule.xml
file use this
<testmodule_index_sayHello>
<reference name="content">
<block type="modulename/block" name="testmodule" template="newpage/content.phtml"/>
</reference>
</testmodule_index_sayHello>
If you don't have block of your module then you can use core/template
as block type
add a comment |
In your testmodule.xml
file use this
<testmodule_index_sayHello>
<reference name="content">
<block type="modulename/block" name="testmodule" template="newpage/content.phtml"/>
</reference>
</testmodule_index_sayHello>
If you don't have block of your module then you can use core/template
as block type
add a comment |
In your testmodule.xml
file use this
<testmodule_index_sayHello>
<reference name="content">
<block type="modulename/block" name="testmodule" template="newpage/content.phtml"/>
</reference>
</testmodule_index_sayHello>
If you don't have block of your module then you can use core/template
as block type
In your testmodule.xml
file use this
<testmodule_index_sayHello>
<reference name="content">
<block type="modulename/block" name="testmodule" template="newpage/content.phtml"/>
</reference>
</testmodule_index_sayHello>
If you don't have block of your module then you can use core/template
as block type
answered Jan 11 '17 at 19:00
PiyushPiyush
4,82972054
4,82972054
add a comment |
add a comment |
There are few changes to make to the existing config.xml file. Since now we are using layouts, we will create our own layout file for our module. Lets name our module’s layout file as test.xml. We will place it in our theme/layout folder.
<?xml version="1.0"?>
<config>
<modules>
<Excellence_Test>
<version>0.1.0</version>
</Excellence_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Excellence_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout> <!-- New Section Added -->
<updates>
<test>
<file>test.xml</file> <!-- This is name of the layout file for this module -->
</test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Excellence_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Excellence_Test_Helper</class>
</test>
</helpers>
</global>
</config>
Now create the test.xml file in your theme layout folder. Like in my case its app/design/frontend/default/default/layout/test.xml or if you have create your own theme, put the layout file there. Here are the contents of the file.
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/test" name="test" template="test/test.phtml" />
</reference>
</test_index_index>
</layout>
The explanation of this layout file is given previously here. So the block we used is “test/test” which equal class Excellence_Test_Block_Test and phtml file used is test/test.phtml
So we will create a phtml file in location app/design/frontend/default/default/templates/test/test.phtml
<?php
echo $this->getContent();
?>
In the file, we are calling a function getContent(); this function is to be declared in the block Test.php block file. As we have seen previous, the $this variable here is actually an object of our block class, which we define as ‘type’ in our layout.xml. Just to confirm you write below code in your phtml file.
<?php echo get_class($this); ?>
The output should be Excellence_Test_Block_Test.
Now create the file Test.php at location app/code/local/Excellence/Test/Block/Test.php
<?php
class Excellence_Test_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
Now, to call all these layouts we need to make some changes in the IndexController.php
<?php
class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(); //This function read all layout files and loads them in memory
$this->renderLayout(); //This function processes and displays all layout phtml and php files.
}
}
Open the url www.your-magento.com/test/ again and it will again print ‘helloword’.
add a comment |
There are few changes to make to the existing config.xml file. Since now we are using layouts, we will create our own layout file for our module. Lets name our module’s layout file as test.xml. We will place it in our theme/layout folder.
<?xml version="1.0"?>
<config>
<modules>
<Excellence_Test>
<version>0.1.0</version>
</Excellence_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Excellence_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout> <!-- New Section Added -->
<updates>
<test>
<file>test.xml</file> <!-- This is name of the layout file for this module -->
</test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Excellence_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Excellence_Test_Helper</class>
</test>
</helpers>
</global>
</config>
Now create the test.xml file in your theme layout folder. Like in my case its app/design/frontend/default/default/layout/test.xml or if you have create your own theme, put the layout file there. Here are the contents of the file.
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/test" name="test" template="test/test.phtml" />
</reference>
</test_index_index>
</layout>
The explanation of this layout file is given previously here. So the block we used is “test/test” which equal class Excellence_Test_Block_Test and phtml file used is test/test.phtml
So we will create a phtml file in location app/design/frontend/default/default/templates/test/test.phtml
<?php
echo $this->getContent();
?>
In the file, we are calling a function getContent(); this function is to be declared in the block Test.php block file. As we have seen previous, the $this variable here is actually an object of our block class, which we define as ‘type’ in our layout.xml. Just to confirm you write below code in your phtml file.
<?php echo get_class($this); ?>
The output should be Excellence_Test_Block_Test.
Now create the file Test.php at location app/code/local/Excellence/Test/Block/Test.php
<?php
class Excellence_Test_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
Now, to call all these layouts we need to make some changes in the IndexController.php
<?php
class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(); //This function read all layout files and loads them in memory
$this->renderLayout(); //This function processes and displays all layout phtml and php files.
}
}
Open the url www.your-magento.com/test/ again and it will again print ‘helloword’.
add a comment |
There are few changes to make to the existing config.xml file. Since now we are using layouts, we will create our own layout file for our module. Lets name our module’s layout file as test.xml. We will place it in our theme/layout folder.
<?xml version="1.0"?>
<config>
<modules>
<Excellence_Test>
<version>0.1.0</version>
</Excellence_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Excellence_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout> <!-- New Section Added -->
<updates>
<test>
<file>test.xml</file> <!-- This is name of the layout file for this module -->
</test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Excellence_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Excellence_Test_Helper</class>
</test>
</helpers>
</global>
</config>
Now create the test.xml file in your theme layout folder. Like in my case its app/design/frontend/default/default/layout/test.xml or if you have create your own theme, put the layout file there. Here are the contents of the file.
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/test" name="test" template="test/test.phtml" />
</reference>
</test_index_index>
</layout>
The explanation of this layout file is given previously here. So the block we used is “test/test” which equal class Excellence_Test_Block_Test and phtml file used is test/test.phtml
So we will create a phtml file in location app/design/frontend/default/default/templates/test/test.phtml
<?php
echo $this->getContent();
?>
In the file, we are calling a function getContent(); this function is to be declared in the block Test.php block file. As we have seen previous, the $this variable here is actually an object of our block class, which we define as ‘type’ in our layout.xml. Just to confirm you write below code in your phtml file.
<?php echo get_class($this); ?>
The output should be Excellence_Test_Block_Test.
Now create the file Test.php at location app/code/local/Excellence/Test/Block/Test.php
<?php
class Excellence_Test_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
Now, to call all these layouts we need to make some changes in the IndexController.php
<?php
class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(); //This function read all layout files and loads them in memory
$this->renderLayout(); //This function processes and displays all layout phtml and php files.
}
}
Open the url www.your-magento.com/test/ again and it will again print ‘helloword’.
There are few changes to make to the existing config.xml file. Since now we are using layouts, we will create our own layout file for our module. Lets name our module’s layout file as test.xml. We will place it in our theme/layout folder.
<?xml version="1.0"?>
<config>
<modules>
<Excellence_Test>
<version>0.1.0</version>
</Excellence_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Excellence_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
<layout> <!-- New Section Added -->
<updates>
<test>
<file>test.xml</file> <!-- This is name of the layout file for this module -->
</test>
</updates>
</layout>
</frontend>
<global>
<blocks>
<test>
<class>Excellence_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Excellence_Test_Helper</class>
</test>
</helpers>
</global>
</config>
Now create the test.xml file in your theme layout folder. Like in my case its app/design/frontend/default/default/layout/test.xml or if you have create your own theme, put the layout file there. Here are the contents of the file.
<?xml version="1.0"?>
<layout version="0.1.0">
<test_index_index>
<reference name="content">
<block type="test/test" name="test" template="test/test.phtml" />
</reference>
</test_index_index>
</layout>
The explanation of this layout file is given previously here. So the block we used is “test/test” which equal class Excellence_Test_Block_Test and phtml file used is test/test.phtml
So we will create a phtml file in location app/design/frontend/default/default/templates/test/test.phtml
<?php
echo $this->getContent();
?>
In the file, we are calling a function getContent(); this function is to be declared in the block Test.php block file. As we have seen previous, the $this variable here is actually an object of our block class, which we define as ‘type’ in our layout.xml. Just to confirm you write below code in your phtml file.
<?php echo get_class($this); ?>
The output should be Excellence_Test_Block_Test.
Now create the file Test.php at location app/code/local/Excellence/Test/Block/Test.php
<?php
class Excellence_Test_Block_Test extends Mage_Core_Block_Template
{
public function getContent()
{
return "Hello World";
}
}
Now, to call all these layouts we need to make some changes in the IndexController.php
<?php
class Excellence_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout(); //This function read all layout files and loads them in memory
$this->renderLayout(); //This function processes and displays all layout phtml and php files.
}
}
Open the url www.your-magento.com/test/ again and it will again print ‘helloword’.
edited Jan 11 '17 at 18:58
answered Jan 11 '17 at 18:42
Vishal ThakurVishal Thakur
429512
429512
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f154293%2fmagento-unable-to-load-my-custom-layout-through-controller%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Is that the entire config.xml and controller file? What do you see in your browser? Do you have a layout file? Can you post it? As this question stands, there's nowhere near enough information to start on it...
– tjons
Jan 11 '17 at 16:26
add your
testmodule.xml
from layout folder and block code– sandip
Jan 11 '17 at 16:27
<?xml version="1.0"?> <layout version="0.1.0"> <testmodule_index_sayHello> <reference name="content"> <block name="testmodule" template="newpage/content.phtml"/> </reference> </testmodule_index_sayHello> </layout>
– Soumen Kumar Saha
Jan 11 '17 at 16:27
I am able to see the default page of my theme, but I want to display the contents of my conent.phtml file , where I have added my HTML stuff
– Soumen Kumar Saha
Jan 11 '17 at 16:31
@SoumenKumarSaha for creating module you need to follow some basic steps.....as i written bellow (by Vishal Thakur). Just edit module name (Excellence_Test) as you want.
– Vishal Thakur
Jan 11 '17 at 19:19