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. :)

2 Answers 2


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>
  • I dont think it would solve my problem. Reason is I wanto programmatically include a template. Aug 14, 2014 at 14:21
  • This is an untested approach for layouts. You mentioned in your question you wanted to use layouts if possible and this is a way to connect a layout with some code. It is up to you to make it work, but with some logic it might actually work in a clean way.
    – mbalparda
    Aug 14, 2014 at 14:26
  • Ok.. I will make a look on your suggestion. If it worked I will let you know. :) Aug 14, 2014 at 14:28
  • I have a doubt. I think ifconfig points to system -> configuration section. But in my case, I am using syste config. Aug 14, 2014 at 14:37
  • I dont understand the difference. Also the trick is in <url helper> and not in that ifconfig.
    – mbalparda
    Aug 14, 2014 at 14:50

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.

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.