- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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:
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.
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content