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

Using Style Properties in PHP

Discussion in 'XenForo Development Discussions' started by Brogan, Jan 4, 2014.

  1. Brogan

    Brogan XenForo Moderator Staff Member

    I'm guessing this isn't possible but I thought I'd ask anyway.

    My add-on has a style property to disable the sidebar.
    If I can also disable it in PHP I can save 2 queries.

    Unfortunately I can't seem to find a way to use the SP variable in PHP.
    I can of course create an option and use that (e.g. XenForo_Application::get('options')->ctaFtSidebar;) but it's a clunky solution as I then need both an option and a Style Property, or just the option but as it's related to styling/layout it doesn't really make sense.

    Has anyone managed to get it working using just an SP?
    Last edited: Jan 4, 2014
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    Without access to the code right now, you should be able to use the Style Property model to access them.
  3. Brogan

    Brogan XenForo Moderator Staff Member

    Me and Chris tried a few things but couldn't get it to work.

    Dumping these just resulted in string(0) "" in every case.
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    Looking at the code, XenForo_Template_Helper_Core::styleProperty() just internally accesses XenForo_Template_Helper_Core::$_styleProperties, which is empty unless you setStyle properties.

    Try this:
    Obviously, the 1 needs to be replaced to support multiple styles (I'll need to look into it some more to find out how to figure that out in a controller).
  5. Marcus

    Marcus Well-Known Member

    Is the model accessed on any page view (should be, but I do not know how "fetch templates as files" are implemented")? Because from my understanding if it would not, there might be additional database queries.
  6. Marcus

    Marcus Well-Known Member

    If nothing else works, you can just use a acp option which is accessible without any additional query. Not that elegant putting style options in acp, though.
  7. Brogan

    Brogan XenForo Moderator Staff Member

    Yes, I've got it working with an option but the logical place for the checkbox is in SPs.

    What's also annoying is I can't link to the option from the SP as the description fields don't support HTML.

    So admin's will have to be aware that the option needs to be enabled first, before the SP.

Share This Page