• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Changing page style with Code Event Listener

Jon W

Well-known member
#1
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.
 

James

Well-known member
#2
You might be able to use the load_class_route_prefix code event listener and change the page style if the route prefix matches.
 

Jon W

Well-known member
#3
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?
 

James

Well-known member
#4
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.
 

Jon W

Well-known member
#5
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?
 

Jon W

Well-known member
#7
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.
 
R

ragtek

Guest
#9
Calling
PHP:
 $this->setViewStateChange('styleId', $styleId);
inside of the controller should do this!
 

Jon W

Well-known member
#10
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)?