How can I add a block through XML layout file, and not programaticaly, through controller?
I have my block and I want to use it in a template that already exists (catalog/category/view.phtml).
How can I do this without going in and changing a controller, and without changing the catalog/category/view.phtml directly?
I want to add this block somewhere in an already existing template through XML, and not programatically.
This is part of my block:
class Mynamespace_Mymodule_Block_Myblock extends Mage_Core_Block_Template
{
public function _construct()
{
$this -> setTemplate("mynamespace_mymodule/myblock.phtml");
return parent::_construct();
}
public function getItemsByCategoryAndUseState($category, $use_state) {
return "some used or new items";
}
}
This is config.xml of my module:
<config>
<modules>
<Mynamespace_Mymodule>
<version>3.0.0.1</version>
</Mynamespace_Mymodule>
</modules>
<global>
<blocks>
<mynamespace_mymodule>
<class>Mynamespace_Mymodule_Block</class>
</mynamespace_mymodule>
</blocks>
</global>
<frontend>
<layout>
<updates>
<mynamespace_mymodule>
<file>mynamespace_mymodule.xml</file>
</mynamespace_mymodule>
</updates>
</layout>
</frontend>
This is my package/theme/layout/mynamespace_mymodule.xml:
<layout version="0.1.0">
<catalog_category_view>
<reference name="product_list">
<block type="mynamespace_mymodule/myblock" name="myblock" after="-" />
</reference>
</catalog_category_view>
</layout>
Thanks.