cancel
Showing results for 
Search instead for 
Did you mean: 

How to find name of block

How to find name of block

I have created my package based on "rwd" magento 1.9. When I click on a category, say, Women I go to page frontend/my_package/default/template/page/1column.phtml (template hints). In the middle of this page there is a block with template hint: frontend/base/default/template/catalog/category/view.phtml and Mage_Catalog_Block_Category_View. I want to place my module which has subcategories with images into this block. I just can't find the name of the block to insert into. In my layout file I want something like:

<catalog_category_view>
<reference name="????????">
<block type="women/subcategories" name="subcategoriesblock" as="subcategoriesblock" template="subcats/subcats.phtml"/>
</reference>
</catalog_category_view>

I have used $blocks = Mage::app()->getLayout()->getAllBlocks(); to get block names in current page and have tried and tested the various block names but nothing seems to work. Could somebody help and give some suggestion as to how I might get the name of the relevant block. All help will be greatly appreciated.

3 REPLIES 3

Re: How to find name of block

Please check below code

$block = Mage::app()->getLayout()->getBlock('root');
$childBlockNameCollection=$block ->_sortedChildren;
echo "<pre>";
print_r($childBlockNameCollection);

Re: How to find name of block

The easiest way is to add the display of the block name with its class in the hints. You can do this by rewriting the file app/code/core/Mage/Core/Block/Template.php in code pull local and modify its code in the following way (approximately in the line 229):

          if (self::$_showTemplateHintsBlocks) {
                $thisClass = get_class($this);

Replace with:

          if (self::$_showTemplateHintsBlocks) {
                $thisClass = get_class($this) . ' --- Name: ' . $this->getNameInLayout();

The result with activated hints will be the following:

ed853d66f8d655e3c59a68339d383015.png

As you can see, all block names in layout are specified with --- Name: from the class name. It is very comfortable for developers, but you shouldn't forget about class in code pull local during updates and debug.

Re: How to find name of block

You can try with <reference name="product_list">
 
You can also look in to the /frontend/base/default/layout/bundle.xml  file, it is also using the same tag.