User Preferences -> Style Variable?

king8084

Well-known member
Is there a way to identify the user's preferred/default style setting via a xen variable?
i..e, how can I identify what's here: ACP > Users > Preferences > Style

I've taken a look at '$visitor', however, I'm not seeing anything that will point me to that particular data point (am I overlooking it? or is it stored elsewhere?). '$visitor.style_id' isn't it, as that strictly displays the style that's being displayed on the screen, rather than looking to the user's preferences directly.

...context: I use Turnkey Mobile Apps , which only allows for a single pre-defined style to be utilized. I'm thinking through a way in which I can use a combination of js & css to conditionally display the single App style in various color palettes, using the user's desktop preference as a driver. ex: if their desktop style pref is set to our "day theme" then i will display things in white on the app style, if it's set to "night theme" then i will display things in black on the app style (generalized statement).

Thanks.
 
$visitor.style_id should always point to the value stored in the xf_user table, unless there is something overwriting it.

I just set up a quick test to test this.

Have two styles, e.g. style_id 1 and style_id 2.

Set your preferences to use style_id 2.

Edit any forum and set "Override user style choice" to style_id 1.

Edit the forum_view template in the style_id 1 and add the following:
Code:
xf_user.style_id = {xen:helper dump, $visitor.style_id}
<br />
effective style.style_id = {xen:helper dump, $visitorStyle.style_id}

Now visit the forum you set the style override on, you will see:

xf_user.style_id =
int(2)

effective style.style_id =
int(1)

What this demonstrates is that regardless of what overrides the style being viewed, the value of style_id in the visitor object should always be what the user has selected.

It is worth noting that the style_id by default would be 0 for users. In this case, the user's actual style ID would be equivalent to the following (if not overridden elsewhere):

Code:
{xen:if '{$visitor.style_id}', '{$visitor.style_id}', '{$xenOptions.defaultStyleId}'}

If this isn't consistent with what you're seeing then it's possible that something is overriding the style_id value in the visitor object; that would in theory work, but it isn't the correct way to override a user's effective style.
 
Back
Top Bottom