XF 2.1 Access visitor's style properties in addon's PHP class

nocte

Well-known member
How can I access style properties of the style the visitor is currently using in an addon's PHP class?

This gives me the default style's background color:

PHP:
\XF::app()->style()->getProperty('contentBg');

but I need the one of the current visitor's style.

Edit: the code above does not translate LESS style properties to proper CSS. 🤔
 
Last edited:
Thank you!

This one is left:
Edit: the code above does not translate LESS style properties to proper CSS. 🤔
I tried:
PHP:
\XF::app()->style(\XF::visitor()->style_id)->getCssProperty('contentBg');
but this does not give me an output.
 
.\XF::app()->style(\XF::visitor()->style_id)->getProperty('contentBg');
I tried that already (see above), but it gives me LESS output, e.g. xf-intensify(@xf-contentBg, 7%). I need CSS-usable colors.
 
.
PHP:
$app = \XF::app();

$templater = $app->templater();

$style = $app->style(\XF::visitor()->style_id);

$color = $templater->func('parse_less_color', [$style->getProperty('pageBg')]);
 
looks good. 1 line was missing: $templater->setStyle($style);

so we have:

PHP:
$app = \XF::app();

$templater = $app->templater();

$style = $app->style(\XF::visitor()->style_id);

$templater->setStyle($style);

$color = $templater->func('parse_less_color', [$style->getProperty('pageBg')]);

I noticed that xf-intensify() was not working correctly on my dark style, so I found this solution :)
 
Top Bottom