Not logged in. · Lost password · Register
Forum: General Help and Support Templates and Layout RSS
Dynamic stylesheet switching
How to let the user control the stylesheet he wants to use?
Avatar
Hal[PT] #1
Member since Jul 2007 · 3 posts · Location: Lisboa, Portugal
Group memberships: Members
Show profile · Link to this post
Subject: Dynamic stylesheet switching
Hi all,

I'm currently using DokuWiki as a CMS so contents could be changed by people with nearly null knowledge on anything computer-related.

I wanted to add to the pages 5 little buttons that would be able to change the stylesheets. That can be accomplished by using javascript, even if i want to add presistency through cookies usage. But my issue is with exe/css.php, i think. I wanted to change basically some of the color values in style.ini so the page layout keeps the same but the color scheme changes. What i'm asking here is: is the easiest way to accomplish such stylesheet changes the altering of css.php? Or could it be done in a prettier way (like leaving Doku's engine as it is and do it all through a template or plugin)?

My current idea is to pass some parameter to css.php that allows it to use different style.ini files. The "style.ini" string is hardcoded in about 4 places in the file, and i think it's a rather bad idea to change them all for the sake of the "upgrade to the next DokuWiki release" process.

Thanks.
Avatar
Hal[PT] #2
Member since Jul 2007 · 3 posts · Location: Lisboa, Portugal
Group memberships: Members
Show profile · Link to this post
While browsing a little further, I hit http://wiki.splitbrain.org/plugin:multitemplate_styleman which almost (the idea is there... there are just some code changes pending...) offers me a solution: create a css.php wrapper script that rewrites the $conf['template'] variable tricking the real css.php into getting style.ini from some custom directory. This little hack allows me to do my trick while restricting upgrade difficulties to the includes/requires present in css.php, which are a lot more unlikely to change in a near future.

I guess i'll be following that direction now... still if *you* have some better idea I would be glad to hear it :)
Avatar
pchan #3
Member since Apr 2007 · 111 posts · Location: Lille, France
Group memberships: Members
Show profile · Link to this post
Yes, I think that is the best approach. Recently, I was playing with the different color schemes of the battlehorse template. It was very nice but a lot of manual work to make each change effective. I was thinking of using a real CSS selector/switcher see e.g. http://www.alistapart.com/stories/alternate/
Finally, I used the fact that the page is regenerated from scratch at each update and load the required css (I built one for each color scheme). The color change became effective from the configuration page: just push 'SAVE' !

For your question, my comment is that you are on the right track, keep it going!
Avatar
Hal[PT] #4
Member since Jul 2007 · 3 posts · Location: Lisboa, Portugal
Group memberships: Members
Show profile · Link to this post
Thanks for your reply pchan.

At the moment i've successfully implemented a stylesheet changer by using a script similar to the one presented in that article from ALA and a modified version of the multitemplate_styleman plugin. My solution uses the jQuery library and is currently adding the <link> elements to the DOM as needed, which doesn't work on some browsers (just IE, IE and IE) where i have to force a page reload so that the new stylesheet can be fetched from the server. I do this to prevent transfering of 5 stylesheets when I could transfer only one, because they're somewhat big. Since it's such a specific solution, I'm not currently sharing it (it would make no sense, believe me), but if I get some free time i'll try to change it into something more generic so it can be released.

Still, if anyone is in a hurry to get something similar just ask me to send the solution, but you'll have to spend some time adapting it to *your* case.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-05-24, 10:12:58 (UTC +02:00)