2

So I have a situation where I really need to observe an event which is layout handle specific. In my case, I want to set a root template for the handle catalog_category_default. I think I can use controller_action_layout_load_before for this purpose. But as its name indicates it may call every time a controller tries to load a layout(I am not sure about this point). Since there are lot of controllers out there (We all know Magento is a giant system !!), I feel this event is inappropriate in my case. It is enough if I can listen to a catalog controller based layout loading event, so that unwanted observations can be avoided ? So my question is

  1. Can we have particular layout handle based or a particular controller based events ?

  2. If I listen to controller_action_layout_load_before, is that making unwanted observations ? Is it affect magento performance ?

9
  • why dont you modify the template from its block class? that would be specific.
    – huzefam
    Commented Jul 10, 2014 at 10:12
  • i dont like rewrite methods. it is always recommended that, we need use observers if it is possible. Commented Jul 10, 2014 at 10:17
  • as you want to modify a specific handle, then rewrite would be better than getting the observer method called each time
    – huzefam
    Commented Jul 10, 2014 at 10:24
  • Yes. You are correct. But question is a doubt. I need clarification more on this Commented Jul 10, 2014 at 10:27
  • i did check list of events, huztechbuzz.wordpress.com/2014/04/26/… , i could not locate a specific one
    – huzefam
    Commented Jul 10, 2014 at 10:29

2 Answers 2

2
  1. There are some pages that have specific events, but it's not a general case.
    For example, for the category page you have events, catalog_controller_category_init_before and catalog_controller_category_init_after but those are dispatched before the layout is loaded. So you don't have access to the page blocks in those events.
    For the product page you have the events catalog_controller_product_init_before and catalog_controller_product_init but again you don't have access to the layout.

  2. Sure controller_action_layout_load_before will make unwanted observations. It is dispatched for all pages, but I don't think the impact is very big. If you write your observers correctly this shouldn't be visible. I mean, the first thing you should do is to check if your observer is dispached from the right page. If not, just return nothing.

For the rest of you problem, changing layouts in different cases I already wrote an answer here: https://magento.stackexchange.com/a/29329/146

1
  • I learned a lot from you. Thanks for your each and every outstanding answers Commented Jul 18, 2014 at 8:17
1
public function someFunc($observer)
    {
      $action = $observer->getEvent()->getAction();
      $actionName = $action->getFullActionName();
      if($actionName == 'catalog_category_default')
      {
        // your code.
      }
    }
1
  • Please read question. Commented Jul 10, 2014 at 10:18

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.