So, I want to add a custom layout handle for all category view pages.. the handle that is supposed to be loaded depends on certain category parameters, so the handle needs to be added programmatically with
Seems easy..? Apparently not
Magento 2 provides a nice Plugin system that I was naturally going to use, just define a
afterExecute() plugin to be run after the original category
execute() and push any updates into the Page object from there.
Unfortunately, it does not quite work that way.. reason being that the original
execute() method (at the very end) will execute
$page->getConfig()->addBodyClass() -- a call to this method will automatically force the layout to be completely loaded and generated, so any subsequent attempts to add new layout handles to Page are completely useless.
I looked around to find any not-so-elegant-ways to achieve the same thing (still using plugins).. did not find any.
I ended up running my own controller for category view, however, I would not prefer to leave it that way.
So my question is.. how can I add new page layout handles (programmatically) for category view? and do it elegantly.