4

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

  • 1
    why do you need all block names ? and from where you need to get it ? – Rajeev K Tomy Sep 16 '14 at 10:29
  • My custom extension add block name admin – MagikVishal Sep 16 '14 at 10:30
  • 1
    didn't get you. Add more details to your question – Rajeev K Tomy Sep 16 '14 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.. – MagikVishal Sep 16 '14 at 10:40
14

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
    You are genius... hats off u upvote to u – Amit Bera Sep 16 '14 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, privacy policy and cookie policy

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