XF 2.1 Targetting style selection through a link reference in template mod. Is there a better way?

Brad Padgett

Well-known member
So to dumb this down in the simplest way possible I want to know if there is a better way to do this.

Let me break it down. First I'm trying to set a light bulb in the nav bar that goes to a corresponding style_id number set in options.

Basically to go to the dark style and switch back to light when clicked again. A user would place the style_id for each corresponding style in options. So far I got the option part set up.

Note that I want to make this as simple as possible so there should be no class files as I feel something this simple should not need one. So I then made a template mod and used this:

HTML:
<a href="{{ link('misc/style?style_id=', $xf.visitor) . $xf.options.Dark_Switch }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-off.png', true) }}"></a>
    <a href="{{ link('misc/style?style_id=', $xf.visitor) . $xf.options.Light_Switch }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-on.png', true) }}"></a>

You can ignore the img src part. That's merely to get the image to show.

The part I want you to pay attention to is the link.

After setting up the option Dark_Switch and Light_Switch in options the user puts in the style IDs and clicks save.

Now it works and it has been tested. But there is a single issue and that's the dialogue that comes up and asks whether or not I want to switch styles.

For the purpose of this add-on I do not want the dialogue to appear and ask to switch styles.

How can I set the link to automatically go to the corresponding style IDs without the dialogue asking whether or not I want to switch styles. Also is there a better way I should be doing this. Looks a bit too easy but then again I don't want to make a class file because I feel as if it's un-necessary for an add-on this simple and shouldn't be needed.

I will wait on your guys assistance. Going to tag a couple people so if no one responds they might help. @Sim @S Thomas
 
EDIT: I'll just cut it short and sweet for the answer I need.

I did it the right way the first time (unless you know a better way). I just need to know how to stop the dialogue box that asks if your sure you want to switch styles from showing up after the user clicks the light bulb to change styles. @Chris D easy question if anyone knows
 
Last edited:
This url should work without problems, is based on the modification I use for my site :)
HTML:
<a href="{{ link('misc/style', null, {'style_id': $xf.options.Dark_Switch,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-off.png', true) }}"></a>
<a href="{{ link('misc/style', null, {'style_id': $xf.options.Light_Switch ,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-on.png', true) }}"></a>
 
This url should work without problems, is based on the modification I use for my site :)
HTML:
<a href="{{ link('misc/style', null, {'style_id': $xf.options.Dark_Switch,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-off.png', true) }}"></a>
<a href="{{ link('misc/style', null, {'style_id': $xf.options.Light_Switch ,'_xfRedirect': $xf.fullUri,'t': csrf_token()}) }}"><img src="{{ base_url('styles/default/BP/LightSwitch/bulb-on.png', true) }}"></a>

Spoken like a true pro once again @DL6 you never cease to surprise me

Hands down you are one of the most helpful people in this forum. Surprisingly helpful. I haven't tried it yet but knowing you it works like a charm. Appreciate you taking the time to actually put that together. Well done :D
 
@DL6 tested it works without fail. Good lord I'm so happy right now. I may turn this add-on into a style chooser as well. I'm going to see what I can put together. Light Switch for sure but I may include some more options in it. Won't release anything until fully tested. I appreciate your help.
 
@DL6 I have one very last question. Or anyone else who knows.

First I'd like to say that this add-on is almost finished and it's going to be a really good one. I've made a style chooser and you can even change the colors of the preview boxes in style properties. You basically have up to 9 styles you can configure via style ids. There's also the light switch, however that's where my question currently is, with the code you gave me.

I am trying to make it so that I'm able to use more than 2 configurable corresponding light and dark styles. Personally on my site we have 5 light and 5 dark styles. So I wanted to make 5 styles to correspond.

Setting up the style properties I have 5 styles I'd like to match up. Your code will only work with 2 configurable styles. I made the extra style properties and tried using the code more than once but the light bulb shows up multiple times so that doesn't work. I will tag @Chris D maybe he's interested for the sake of a free add-on.

Anyways can you help me with a code that will show 5 light and 5 dark styles that correspond? Afterwords I'll be close to finishing. Got a couple more features I want to add. Thanks for the help
 
@Chris D for the sake of a free add-on do you know how I can use that exact code @DL6 made to add more than one with the light bulb only showing once?

I'm almost finished this is the last thing I need to do before releasing
 
Top Bottom