This really confuses me !!
I came to a situation, where I need to create a new block (core/template
block) programmatically, if there is CMS Block present in a page layout. In general case, according to my knowledge, there are two work around for this.
1. Add a block through layout
In most of the case, this would be the best idea to do this task. We can add a block to a page if an appropriate layout handle is available. But unfortunately, in my case, I dont have any static block specific layout handle available (for cms pages, we know there is cms_page
handle). So I can't rely on this method
2. Use an observer
The second method would be listen to an appropriate observer. Again, I cannot find a static block based observer that get triggered during layout/block loading time. However there are some general observers that I can rely on. I think controller_action_layout_generate_blocks_before
can use in my case. But here I am facing my real problem
My real Problem
So when I use controller_action_layout_generate_blocks_before
event in my case, the problem is that, I cannot retrieve blocks based on their type. I can filter blocks based on their name
, but not based on their type
. ie
$observer->getEvent()->getLayout()->getBlock('block_name'); //this work; Used name
$observer->getEvent()->getLayout()->getBlock('cms/block'); //this wont; use type
I cant rely on names in fact. Because I want to get all cms/block
type blocks and add a new template after checking some of their custom property that I have set with static block
So how can I get all cms/block
through an observer ? Is it even possible. Please share your thoughts.