2

I am currently trying to load a custom layout handle after the catalog_category_view handle through the use of an observer that looks for the event catalog_controller_category_init_after.

The layout handle works when removing blocks, however ignores any layout update that adds a block to the layout.

Am I using the correct event to load the handle? Is there a better way of loading the custom layout handle?

  • can you post your layout update? – Marius Feb 19 '15 at 12:35
  • Hi Marius, Its not so much the update that's the problem but the actual loading of the handle. If I change the layout handle of my custom handle to <catalog_category_view> it works fine. As soon as I change it back to <new_catalog_category_view> it removes the specified blocks contained inside but doesn't add the blocks. – Ryan Copeland Feb 19 '15 at 12:45
1

This is because catalog_controller_category_init_after is triggered before the layout is loaded. That means, if you add a layout handle in the observer for this event, it is the first one, before catalog_category_view, even before default. So any block you are referencing in your handle does not exist yet.

The <remove> tag works differently, it operates on the fully merged XML tree, that's why you can remove blocks. But instantiating blocks and executing actions happens in order of definition.

Solution

Use a different event. A good choice is controller_action_layout_render_before_catalog_category_view which is triggered immediately before the layout is rendered, so you can be sure that it has been fully loaded.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.