Get all blocks from a certain handle or routes

I am looking for a way to get all blocks belonging to a certain handle or route, for example get all blocks within catalog_product_view. Is this possible without looping through all XML files?

The main goal is getting the block name by the template attribute, since this is displayed by the profiler. But so far I am unable to figure this out.


I want to hide certain blocks ( in the frontend) from a menu in the Magento backend. Since blocks may differ from theme to theme I decided to just make a field where users put in the block name. Then observe if this configuration field is set and if it is remove this block before it's get rendered.

This works great, but most users do not know where to find the block name, so they are unable to do this. So I was thinking how to simplify this process and thought they could turn on their profiler so they could look up the block they needed to remove. Unfortunately the profiler does not give the block name and shows only an alias and the template file.

Since not every block has an alias but every ( displayed ) block has an template file i decided instead of a block name they could just enter the template file path given by the profiler for the specific block and observe the save event of the config page and automaticly find the corresponding block name. This however seems to be a challenge.

  • Update: I was unable to achieve a good workflow, for now I leave it be. If someone does know a good solution for this, i'd love to hear. If I find some spare time I think I will look into extending the profiler some how to achieve an understandable workflow.
    – rofavadeka
    Jun 18, 2015 at 8:03

1 Answer 1


I've not really understand your goal.

I think there're multiple ways to get all blocks used in a specific handle or route. Here is one solution :

  1. Create an observer on event controller_action_layout_generate_blocks_after (more details in Mage_Core_Controller_Varien_Action class)
  2. This event is dispatched with the layout object, so you can use the getAllBlocks() method from the Mage_Core_Model_Layout class

By doing $observer->getEvent()->getLayout->getAllBlocks(), it will return an array containing all block objects that the route has generated.

  • Sorry, I know i can observe an event if the view in question loads, this is not what i am trying to do. I will clarify my question and elaborate a bit on this. See question above.
    – rofavadeka
    Jun 5, 2015 at 11:24

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.