I'm interested in using ThemeKey for a mobile site. What I'd like to do is switch the theme based on the device and the site stick to that theme for the duration of the user's session. I can use a mobile detection script (PHP) and then add a query string to the url for the front page, but would that be the best way to use this? I'm not sure I could keep up with the myriad of agent strings in mobile world to use that for the theme switch.

Comments

mkalkbrenner’s picture

You can use the properites system:user_browser_simplified and system:user_os_simplified to detect diferent mobile devices. One of the tutorials included in ThemeKey uses system:user_os_simplified to detect iOS.

If you enable ThemeKey Debug you can see the values of these properties when you access the page. I suggest to install the Firefox extension User Agent Switcher to do so.

From my point of view there's no need to use another mobile detection script. But could you provide a link to that script, so we can see if we miss something in our code?

jaarong’s picture

This is the script that someone pointed me in the direction of using. I use it now on our main Drupal site to redirect all mobile devices to the mobile site.

http://detectmobilebrowsers.mobi/

emptyvoid’s picture

It would be interesting to either integrate with or think about building a token/theme key bridge to leverage the module WURFL API or the mobile tools modules.

For those interested here are two modules that address mobile. However it would be interesting to bridge the functionality and make it available within theme key.

http://drupal.org/project/wurfl

http://drupal.org/project/mobile_tools

jaarong’s picture

What I ended up doing is using ThemeKey system:user_os_simplified to identify whether it was an iPhone, Android, or Blackberry. Everything else gets the simpler template. This works, but it has the same problem that I've found with every other mobile detection through php, you can't use cache. Since mobile doesn't get the numbers to really justify caching, it's fine for now, but I'm sure it will get to a point where it won't be.

mkalkbrenner’s picture

@#4 subnet_rx:

I had a quick look at the mobile_tools module. I think it's theme switching does not support page caching as well.
But you can try this:

Use mobile_tools to redirect the mobile devices to subdomain like mobile.example.com. Then use ThemeKey Properties 6.x-2.x in combination with ThemeKey 6.x-3.x to create a rule that matches the subdomain using system:host. Now you should be able to use page caching because mobile_tools uses hook_boot for the device detection and page caching uses the sub domain as part of the cache id.

I did't try it, but I guess it will work.

emptyvoid’s picture

Interesting idea @mkalkbrenner I could also use the Domain Access module to split out each domain and write a few hooks to enable theme key to be domain access aware.

Domain Theme may do the trick or maybe using the hook_domainconf() to set theme key per domain settings.

http://api.therickards.com/api/function/hook_domainconf/domain

module I mention.
http://drupal.org/project/domain

jaarong’s picture

I do split out the domain, but the detection across the board (from what I understand) is php. So, you wouldn't be able to detect that it was a mobile phone and send it to the mobile site if caching was on. Then, when it gets there, I need to know what kind of mobile phone so I can display the correct theme.

Right now, we use JS for detecting if it's a mobile phone, and simply display a banner to promote the mobile site. Since JS detection is kind of spotty, we don't automatically redirect. I've read about some techniques using Varnish that help with caching and detection, but we don't use Varnish as our caching server.

atisa’s picture

I have used Domain Access module to add multiple sub-domains to my Drupal site. Each sub-domain has its own theme, blocks, contents and menu but some of the contents are shared among the sub-domains. In general my website looks like this:

sub1.example.com
sub2.example.com
sub3.example.com
sub4.example.com

I can use Mobile_tools module to set up one of these domains, but what can I do for the rest of the sub-domains?

mkalkbrenner’s picture

@atisa:
First you have to decideto use mobile tools OR themekey.

atisa’s picture

I would like to use Themekey but in order to solve the cache problem I want to assign different URLs for mobile visitors. So I decided to use Mobile Tools to define mobile URL for each of the subdomains. But Mobile Tools only accepts one desktop url and one mobile url. If there is any way that I can solve the cache problem with Themekey I would definietly use Themekey module. Any suggestions would be appreciated.

mkalkbrenner’s picture

I don't see why mobile tools or drupal itself are used to setup sub domains.
That's a part of your webserver and dns configuration.

My recomandation:
1. unistall mobile tools
2. setup your webserver and dns to make your drupal installation accessible via different sub domains (in your case 8 sub domains, 4 for your normal sites and Domain Access and 4 mobile sub domains)
3. configure theme key to use different themes for different sub domains

I hope that this works, but domain access is known not to be compatible with anything else.

BTW which version of themekey are you using?

atisa’s picture

Thanks for your response. I have already setup my server and all the sub domains are accessible. Themekey works perfect with theme switching and all the subdomains have their themes assigned through Themekey. The problem is that if the device is mobile I need to switch the url from sub1.example.com to m.sub1.example.com and from sub2.example.com to m.sub2.example.com and ... I do not think that can be done with Themekey!
And to answer you question about my Themekey's version, I am using version 6.x-4.0.

mkalkbrenner’s picture

OK. So the remaining issue is the redirect to a mobile sub domain. This could be done by a few lines of php code. But I don't know a module for that ...

mkalkbrenner’s picture

Status: Active » Closed (fixed)

no feedback

suncorjohn’s picture

subnet_rx how did you setup the system:user_os_simplified settings in Themekey?

Did you just use:
system:user_os_simplified = android, iphone, blackberry

Thx,

John

olivm_fr’s picture

John, you may use system:user_os_simplified ~ (Windows Phone|iPhone|iPad|Symbian|webOS|Android|Blackberry)

Olivier