Changing page style with Code Event Listener

Jon W

Well-known member
Is it possible to change the (default) style of the current page using a Code Event Listener? I am interested in, for example, loading a different style based on the page URL.
 
You might be able to use the load_class_route_prefix code event listener and change the page style if the route prefix matches.
 
Thanks for your suggestion James. Annoyingly, the route prefix that I would have liked to match (the one for the LNBlog Add-on) appears to be called on every page, so this isn't going to work. However, I think I can just look for the "/blog/" in the URL, so that is not a problem.

The problem I am having is actually changing the page style (and, once I've found that, knowing when to change it). Perhaps this is a really simple request, but I am relatively new at XenForo and I can't find the method/variable I need to call/change.

If it is the case that whatever method/variable I need to call/change is accessible in any Code Event Listener, then I can obviously change it in whichever Code Event Listener is called first.

Does that make sense? Can you help?
 
If it's the blog add-on, Onimua should be able to help. Are you wanting to choose the style for the whole blog? If so, you could check if the controller matches and then change the style accordingly.
 
Yer, I want to change the style for the whole blog, so what you have suggested should work. It was also just a general question as I might want to do it for other things.

Any idea how to actually change the style once I've matched the controller?
 
I definitely don't want to do that. I know that you can override a user's style for a particular category or forum, so I was hoping to do something similar.
 
Calling
PHP:
 $this->setViewStateChange('styleId', $styleId);
inside of the controller should do this!
 
Perfect. I think I stumbled upon this before and forgot about it. Is there any way to access the controller from a Code Event Listener though, or is my only option to manually edit the Add-on code (every time it is updated)?
 
(I wasn't expecting you to send the file, not I wasn't expecting it to work like a charm!)
 
Top Bottom