Using Style Properties in PHP

Paul B

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:
Without access to the code right now, you should be able to use the Style Property model to access them.
 
Me and Chris tried a few things but couldn't get it to work.

Dumping these just resulted in string(0) "" in every case.
XenForo_Template_Helper_Core::styleProperty('ctaFtEnablePageSidebar')
XenForo_Template_Helper_Core::styleProperty('ctaFt.ctaFtEnablePageSidebar')
XenForo_Template_Helper_Core::styleProperty('ctaFt')
 
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:
PHP:
XenForo_Model::create('XenForo_Model_StyleProperties')->getEffectiveStylePropertiesInStyle(1);
XenForo_Template_Helper_Core::setStyleProperties($properties, false);
XenForo_Template_Helper_Core::styleProperty('ctaFtEnablePageSidebar');

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).
 
Without access to the code right now, you should be able to use the Style Property model to access them.
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.
 
My add-on has a style property to disable the sidebar.
If I can also disable it in PHP I can save 2 queries.

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.
 
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.
 
Top Bottom