magento required files for creating a block template
It’s pretty complicated to created a frontend template file and insert it into an existing block. Here are the maximum number of magento files you could possibly go through in creating a block template. They are the module config.xml, module block php class, template layout xml, the template file you want to add the new template to and the template file itself. These are the maximum number of files needed for creating an independent and stand alone block template. Otherwise, the module config.xml, module block class can be avoided by using an existing block class.
In the module config.xml
<layout> <updates> <modulename> <file>layout_file_name.xml</file> </modulename> </updates> </layout>
In the Ablock.php in the Block folder of your module
<?php class PackageName_ModuleName_Block_Ablock extends Mage_Core_Block_Template { public function hello() { // return a string or you could do any other fancy stuff here and return the reuslts to be used in the phtml template file return "hello"; } }
In the layout_file_name.xml in your design/frontend/theme_name/layout/
<?xml version="1.0"?> <layout version="0.1.0"> <some_existing_block_name translate="label"> <reference name="head"> <block type="module/ablock" name="name_of_this_block" template="path/to/a/template/file.phtml" /> </reference> </some_existing_block_name> </layout>
In the some_existing_block_name template file it has to call this template file you want include.
echo $this->getChildhtml("name_of_this_block");
In the file.phtml template file itself.
<?php echo $this->hello();
Search within Codexpedia
Search the entire web