4

I want get all used block names of current pages kindly reply me

4
  • 1
    why do you need all block names ? and from where you need to get it ? Sep 16, 2014 at 10:29
  • My custom extension add block name admin
    – Vishal
    Sep 16, 2014 at 10:30
  • 1
    didn't get you. Add more details to your question Sep 16, 2014 at 10:33
  • in my extension user can add product blocks like product.list,search_result_list..after that depends on adding blocks add follow next conditions..
    – Vishal
    Sep 16, 2014 at 10:40

2 Answers 2

15

Use this:

$blocks = Mage::app()->getLayout()->getAllBlocks();

This will give you an array with the block instances. To get only the names use this:

$blockNames = array_keys($blocks);
1
  • 1
    You are genius... hats off u upvote to u
    – Amit Bera
    Sep 16, 2014 at 12:12
3

Magento,get list child of a block using _sortedChildren variable of this block object

Suppose if want get all child block name of root block then

justblock from layout and fetch block and get list of child block name:

$block = $this->getLayout()->getBlock('root');

 $childBlockNameCollection=$block ->_sortedChildren;
  echo "<pre>";
 print_r($childBlockNameCollection);
 echo "</pre>";

Do recursive function get all list of child block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.