By tyswan on
I have a custom theme based on Andreas, which is visually nice and quiet.
I have also enabled the Pushbutton theme for its accessibility properties.
Andreas will be my default theme, but I want to have an Acessability block on the main page which allows users with impairments to switch across to the Pushbutton theme with a single click, and toggle back if they've clicked accidentally.
I want this to work for non-authorised users, not just registered users.
The theme switching I've seen in the forum seems to relate to pre-phpTemplate implementations.
Would something like:
$GLOBALS['custom_theme'] = 'mytheme/admin';
from this post
Be the place to start?
Thanks for any and all suggestions,
Tys.
Comments
Switchtheme Module
What about the Switchtheme Module?
Switchtheme rocks
FYI I was looking for a similar solution today and came across this post-- just started using Switchtheme module and it's exactly what I needed (thanx all).
I need to do similar
Hi Tyswan,
I posted a similar question just a few days ago...
http://drupal.org/node/86058
I had a few thoughts how to do this but would like to go one stage further and remove all images - producing a text only site.
BTW what is it that pushbutton has that makes it better for accessibility? I see it has priority 3.
here is my solution
in genetik.ufku.com i use a custom module for changing things in drupal. in this module's hook_init function i use theme switch according to theme name coming from $_GET;
and in my theme files i create links having '&tema=themename' string at the end, to make one-click switch.
note: this code is for adding switch between two themes named mavi and yesil. additionally it adds the link to primary links.
--
Geneticists from METU
Custom module?
Thanks ufku,
Is the first block of code the Module? So just save the code as something.module? I've not created a module before.
Has anybody got any ideas about a Text besed themes, removing images from posts? Could this be done with template.php in the text theme?
Mark
to make it work
put the first block of code inside something_init() {} function and save it as something.module.
--
Geneticists from METU
Thanks
Thanks ufku,
I'll give it a go.
Mark
Example module
Somebody contacted me to ask about this code, and how to get it working. I've made some changes, more for my own benefit such as changing $tema to $style etc.
Thanks to ufku for his original example code.
The code that goes inside the module, called access_theme.module
Call it whatever you want but match the function names in the module too.
Put it in your module folder and enable it.
I then created a custom block because I needed to hard code some access keys. It does the job for me.
I created a new block (input type php), inserted the code below. I enabled the block in a region in this case a custom region called 'support links'.
Alternatively you can place the following code somewhere in each theme page.tpl.php
This puts the link in the Primary Nav, but it doesn't change the text link - should be easy enough to adapt though, using the if else statement from above.
The text only module is basically a duplication of my graphic theme with some preg_replace to strip out images and replace with the alt text.
eg. in block.tpl.php
In use on a site:
http://www.clubmark.org.uk
Mark
For 5.1 and without clean URLS
This is really good, but I had a few problems implementing this, so I thought I'd document how I dealt with them here.
First, for modules in Drupal 5.1 there needs to be a (modulename).info file included as well (see http://drupal.org/node/82936).
This is pretty easy to do, so you'll need to make a folder/directory and put the .info file and the .module file (from Mark's post above) in there, and upload the whole folder to your site (sites/all/modules)
Here's my .info file
I then created a block using similar code to that used by Mark above (I'd already set up an alternate theme to switch to and uploaded and enabled that)
All worked well, except on the home page, where the switching didn't work at all. I could switch themes on the other pages and navigate to home and have it show as text only/graphic version, but on the home page, the link to switch would not work at all.
I think my problem was not having clean URLs. So on the home page the GET function would pull only '/' from the current page URL and the 'view text only version' link would return http://www.mysite.com/&style=text-only
Now without clean urls, this has no effect, I needed to make the 'view text only version' link have a '?q=' in it.
I always enable the rename URL module on my sites and then assign a particular page as the home page in site settings, so my home page is something like:
http://www.mysite.com/index.php?q=home
So to get the code in my block to generate this I add:
immediately after the line:
All this does is say: If we're on the home page then make the $uri variable '?q=home' instead of '/' so that the ' 'view text only version' link will return http://www.mysite.com/?q=home&style=text-only (If you're wondering 'What about the 'index.php' part of the url?' - as far as I know, it's not necessary to include that )
NOTE: This actually diverts you away from the home page to the node that you have set as the home page. There is a difference, so you may need a bit of experimenting to get it right.
I hope that is of use to someone!
P.S. Accessibility note: When validating this over at the w3c validator I got the 'Ampersands (&'s) in URLs' problem (see http://www.htmlhelp.com/tools/validator/problems.html#amp). Because we are passing '&style' to the URL we should use
instead.
Duplicated '&style=XXX'
I've tried to use the code you have outlined above (Mark) using the custom block to place the link.
The theme will switch for me fine once, from one theme to another. When I'm in the second theme however, the link source changes from
www.example.com/node&style=text_onlytowww.example.com/node&style=text_only&style=text_only.Clicking on this link has no visible effect, other than adding an extra '&style=text_only' to the URL in the address bar.
At first I thought my problem lay with the changes I made to your code. After much fiddling, I even copied and pasted your code exactly and renamed my themes to "clubmark" and "text_only", but to no further luck.
I'd appreciate any help on this. Please let me know if I can give any other relevant information.
Thanks,
Dave
//clean uri to prevent multiple style=... strings
Hi Dave,
Are you developing on a local server? Post a few details about the setup and names of the modules.
The module was created for 4.7 and it was quite a while ago. I think I remember initially having a similar problem.
The block output is commented...
Might be something to do with that but I'm not sure without knowing a bit more about your setup.
Mark
Hi Mark, thanks a million
Hi Mark,
thanks a million for your help. I've managed to get this working now though.
I was using two themes, based off the one page template, with seperate css files. When it changed for me once (but not back again) I knew it was working to some degree. I decided to output variables to my page until I found one that always matched the theme I was using.
I'm not too sure on the variables still (still learning php/Drupal), but thought the problem might lie with:
if ( $GLOBALS['theme']=='text_only' )so I changed this line to:
if ($_SESSION['style']=='text_only')which seemed to work OK. Couple more changes to the site & I've ended up with seperate page template files for the two themes. So rather than any variables I've just inserted the following code into each template:
<a href="'.$uri.'&style=[THEME_NOT_IN_USE]" rel="nofollow">[TEXT FOR LINK]</a>Cheers again for the code & for your help!
Dave
Thanks everyone
Hey, glad you guys have come up with the answers whilst I've been asleep for the last couple of days (*yawn*).
Gumgum and Mark, thanks for the tip on the SwitchTheme module. I've read those module lists 100 times, but it changes so fast, and there are so many of them that I missed that. Looks exactly what I need - I'll check it out.
ufku, your solution looks more complex than my needs, but thanks for contributing. It looks like you've been able to help out Mark, and I'll come back to your suggestion if SwitchTheme doesn't do it for me.
Mark, I think that the template.php is the correct place to supress images. I haven't looked at a text only site option yet. The other option is to do something with the images in the CSS, but that maybe not quite what you need. And I'm glad this thread is helping you out.
Cheers and thanks to everyone,
--
tys