1

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

dotancohen
1,1306 silver badges21 bronze badges
asked Aug 14, 2014 at 14:05

2 Answers 2

1

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>
answered Aug 14, 2014 at 14:17
5
  • I dont think it would solve my problem. Reason is I wanto programmatically include a template. Commented 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. Commented Aug 14, 2014 at 14:26
  • Ok.. I will make a look on your suggestion. If it worked I will let you know. :) Commented 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. Commented Aug 14, 2014 at 14:37
  • I dont understand the difference. Also the trick is in <url helper> and not in that ifconfig. Commented Aug 14, 2014 at 14:50
1

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.

answered Aug 20, 2014 at 13:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.