I have controller and it has following code:
class Company_ModuleName_NameController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Then I have configured layout XML in my config.xml. Now I would like to add block that points to .phtml file and when user access my controller, that .phtml file would be shown to user.
First of all you should define layout handle for your controller:
Like this:
The you should define where you want to display: content, left, right, another block:
And then you define block which will be displayed:
Where module/blockname is the name of your block. In the example file should be like this:
Company/ModuleName/Block/Blockname.php.
Your config.xml should be also definded properly so magento understood that with ‘module’ thing it should load particularly your class.
Something like this:
UPDATE 1
If you want to simply render some content then you may use Magento’s default block class:
This is how your xml file then will look like:
BUT if you have in your .phtml file something like:
This won’t work. On another side if you have very easy php in your phtml, like below, you don’t need your custom block.