1. 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

Discussion in 'XenForo Development Discussions' started by Jon W, Oct 25, 2011.

  1. Jon W

    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.
     
  2. James

    James Well-Known Member

    You might be able to use the load_class_route_prefix code event listener and change the page style if the route prefix matches.
     
  3. Jon W

    Jon W Well-Known Member

    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?
     
  4. James

    James Well-Known Member

    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.
     
  5. Jon W

    Jon W Well-Known Member

    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?
     
  6. James

    James Well-Known Member

    You can change the user's style, but it won't revert after you've gone out of the blog.
     
  7. Jon W

    Jon W Well-Known Member

    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.
     
  8. James

    James Well-Known Member

    Yeah, you probably need to look in XenForo_Model_Node to find that code.
     
  9. ragtek

    ragtek Guest

    Calling
    PHP:
     $this->setViewStateChange('styleId'$styleId);
    inside of the controller should do this!
     
    James likes this.
  10. Jon W

    Jon W Well-Known Member

    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)?
     
  11. James

    James Well-Known Member

    Code event listener load_class_controller should let you access the controller.
     
    Jon W likes this.
  12. ragtek

    ragtek Guest

    Change the style id in Ragtek_SBS_ControllerPublic_Index

    PHP:
     $this->setViewStateChange('styleId'2);
    upload the files and install the add-on

    should work with beta3
     

    Attached Files:

    Jon W likes this.
  13. Jon W

    Jon W Well-Known Member

    Works like a charm. I really wasn't expecting that. Thank you so much!
     
  14. Jon W

    Jon W Well-Known Member

    (I wasn't expecting you to send the file, not I wasn't expecting it to work like a charm!)
     

Share This Page