cancel
Showing results for 
Search instead for 
Did you mean: 

Using observer to detect page template set via admin

Using observer to detect page template set via admin

I'm trying to allow a user to set a custom category template via the design tab, which is straightforward to implement - however, I want to apply different layout instructions in cases where this specific template has been selected.

 

I'm wondering what a good practice approach would be here - I don't really want the user to have to add custom layout xml in the design tab to generate a custom layout handle I can then work with, as it's another step and not particularly user friendly.

 

On the other hand, I'm not sure the selection of that custom template is enough for me to be able to intercept in a clean way.

 

Would an observer to intercept on 

controller_action_layout_load_before

 to check the category template being used be the only possible/clean solution here?

 

Grateful for any pointers.

4 REPLIES

Re: Using observer to detect page template set via admin

Would it be reasonable for this to be a set of themes, one of which can be selected in the Design tab with the built-in functionality? In each of those themes, you can define your custom category template file, but you can also have a local.xml file to make any layout changes you wish as well. Each of these themes can define a common parent so each of these themes are still very lightweight. 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!

Re: Using observer to detect page template set via admin

Thanks for the reply Tom. 

 

Yes this sounds like the cleanest approach to me. This is already set up as a separate lightweight child theme with a view to it being AB tested against the main theme. The idea being that it would be merged into the main theme following the AB test, however, there's no reason why it can't remain as a child theme at that point. 

Re: Using observer to detect page template set via admin

Actually, this approach didn't work for me in the end due to my situation being a little bit complicated by the AB testing.

 

In the end, I was already using an observer to add category handles based on the category depth, name etc, so I added to that to check for a page layout assigned via the design tab:

 

 if ($pageLayout = $category->getPageLayout()) {
                $update->addHandle($pageLayout);
}

Re: Using observer to detect page template set via admin

Good idea Smiley Happy 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!