Question

So here is the situation. I need to create a core/template block programmatically, if there is CMS Block(Static Block) is present in layout structure. I will use this template to add some content to it dynamically.

If there is any observer for static blocks, I may use it. Another option would be, I can achieve the same through layouts, if there is static block specific layout handle is there (just like cms_page layout handle).

But I couldn't find any observer for static blocks yet. So I can't go with observer. I also look for any static block specific layout handle. That search also made me desperate. I couldn't find one. So the layout updation is also not possible.

So it seems to be the only way that I can achieve this is, to observe any general events(May be controller_action_layout_generate_blocks_after). But I feel it is too bad way..

So what should I do now ? What would be the best method to do this? Can I need to create a custom event listener for static blocks (I don't know whether it is possible !!)? Share your thoughts.

Note : I am creating an extension. I want it as clean as possible. :)

Was it helpful?

Solution 2

It seems that, there is no other way to do this. So I listened the general event controller_action_layout_generate_blocks_after . There I created new block if cms block present.

OTHER TIPS

Maybe you can use a helper in the XML and check for a condition inside it, doing a conditional inside the XML and then act consequently. It might be better than observing each and every block load with an observer.

Here is an answer for doing the XML approach.

<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
    <label>Site Map</label>
    <url helper="catalog/map/getCategoryUrl" />
    <title>Site Map</title>
</action>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top