XF 2.3 Set light variation as default for guests

Actually, that should be doable.

It seems, that XF does check in it's JS files (client side), if the user has set a color scheme. If yes, then a cookie is set.

A dirty way to change this behavior is editing the class XF\Pub\App.

Find:
PHP:
$styleVariation = $request->getCookie('style_variation', '');
Replace with:
PHP:
$styleVariation = 'light'

Not fully tested, but with these changes guests should always should see the light variation of your style.

But, maybe it is possible to do this with an event listener in a much cleaner way.. :)

You should also remove the style chooser for guests in the PAGE_CONTAINER template.

Find:
HTML:
                                            <xf:if is="$xf.visitor.canChangeStyleVariation($xf.style)">
                                                <a href="{{ link('misc/style-variation') }}" rel="nofollow"
                                                    class="js-styleVariationsLink"
                                                    data-xf-init="tooltip" title="{{ phrase('style_variation') }}"
                                                    data-xf-click="menu" role="button" aria-expanded="false" aria-haspopup="true">

                                                    <xf:fa icon="{{ $xf.style.getVariationIcon($xf.visitor.style_variation) }}" title="{{ phrase('style_variation') }}" />
                                                </a>

                                                <div class="menu" data-menu="menu" aria-hidden="true">
                                                    <div class="menu-content js-styleVariationsMenu">
                                                        <xf:macro name="style_variation_macros::variation_menu"
                                                            arg-style="{$xf.style}"
                                                            arg-live="{{ true }}" />
                                                    </div>
                                                </div>
                                            </xf:if>

Wrap this around:

HTML:
<xf:if is="$xf.visitor.user_id">
   <!-- the code above -->
</xf:if>

Instead of this template edit, you can go a much better way and extend the XF\Entity\User::canChangeStyleVariation() method.

Basically you would end up with something equivalent to:
PHP:
    public function canChangeStyleVariation(\XF\Style $style, &$error = null): bool
    {
        if (!\XF::visitor()->user_id)
        {
            return false;
        }

        $styleId = $this->style_id !== 0
            ? $this->style_id
            : $this->app()->options->defaultStyleId;
        if ($style->getId() !== $styleId)
        {
            return false;
        }
        return $style->isVariationsEnabled();
    }
 
You can do this by having two styles, a Default style and a Default style with variations.

pic001.webp

The Default style will have the Enable variations unchecked.

pic002.webp

The Default style with variations has the Enable variations checked.
 
Last edited:
:)

Because I just want to offer dark style, but not prefer it by system settings. But yes, I understand the point. I'll just have to maintain two styles. I just thought variations could be used as a second dark style, but that system setting cannot be disabled.
 
But why? Why explicitly go out of your way to override an explicit choice a user has already made? It's not about what you prefer, surely? A user has already stated a preference, why not just let that happen?
 
I do get this.

I have put a lot of effort into a style I like for the site. It just happens to be a light style. In the past I've developed sites which are dark. I do now have an option for a dark style that is available for paid subscribers as a bonus (there's also different t coloured light/dark styles)

But now (from 2.3) there is a default switch or system style I don't quite know what I'll do. I think the whole concept of people choosing light /dark in their OS kind of didn't register with me so maybe I should not be making it one or the other by default and continue just let the privileged paying subscribers have the luxury of choosing. OR just automatically allowing it go with their system settings.

I haven't yet decided. Could I be losing users purely because there is no system setting than goes with their preferences? If so that would override the current idea of "subscribe to get what you want."
 
I do get this.

I have put a lot of effort into a style I like for the site. It just happens to be a light style. In the past I've developed sites which are dark. I do now have an option for a dark style that is available for paid subscribers as a bonus (there's also different t coloured light/dark styles)

But now (from 2.3) there is a default switch or system style I don't quite know what I'll do. I think the whole concept of people choosing light /dark in their OS kind of didn't register with me so maybe I should not be making it one or the other by default and continue just let the privileged paying subscribers have the luxury of choosing. OR just automatically allowing it go with their system settings.

I haven't yet decided. Could I be losing users purely because there is no system setting than goes with their preferences? If so that would override the current idea of "subscribe to get what you want."
You don't have to use variations. Use extra light and dark style, as you do now.

That's why I wanted to have a switch for the system style in the core, so I can use variations.
 
It's not about what you like more :)

Actually it is.

It's my site - I get to choose exactly how it looks and how my users interact with it.

This is not a democracy - I expect to have 100% control over my site and how it looks.

By asserting that the users get to choose based on their preferences gives them more agency than I, the site owner, have.

Make it a configurable option - there's a reason we have options - to give everyone (including site admins) choices.
 
Although presumably your site would be nothing without users so going out of your way to ignore their preferences is hardly going to be a great start in winning them over.

But indeed. The choice is yours. There are alternatives if you would prefer not to have a system variant by default as mentioned above.
 
Although presumably your site would be nothing without users so going out of your way to ignore their preferences is hardly going to be a great start in winning them over.

The community has been operating for decades without a dark mode option so to asserting that it is my choosing not to allow this by default for guests (who are not members!) that is going to affect the growth is a pretty offensive and ignorant perspective.

People don't come to my site because it looks a certain way - they come because it is the best community around. It is the content and the people who make it that - not how the site looks.

I will bend over backwards for my members (to a degree - it's still my site and my choice) - especially for my paid members - but the guests can sign up as a member if they want any kind of special treatment such as auto-dark mode switching

Indeed, for some of my sites I may want to add this as a premium option for those members who have paid for upgraded features and functionality.
 
Top Bottom