Active
Project:
Virtual Sites
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
24 May 2012 at 11:36 UTC
Updated:
25 Feb 2015 at 16:08 UTC
Jump to comment: Most recent
Hello,
I would like to switch the theme when a condition is satisfied (is mobile).
The problem is that when the cache is enabled, the condition is ignored.
Thank you in advance!
Comments
Comment #1
djg_tram commentedDear me. That must be a Drupal 7.14 issue, I still have a production site with 7.12 where it works flawlessly, so I had no suspicion. I'll look into it.
Comment #2
djg_tram commentedThe plot thickens, see http://api.drupal.org/api/function/hook_custom_theme/7. The second paragraph has a warning about it not working with page cache. I don't know when this text was added but I can't recall having seen it earlier when I ported the module. I'm not yet sure how we can work around this, if it's possible at all.
Comment #3
Clément commentedThank you for your quick response!
It's annoying because no cache Drupal is really slow!
The solution might be to disable the cache when the condition is required to switch theme?
Comment #4
Clément commentedI found a solution!
(with module : mobile theme)
Comment #5
djg_tram commentedVery nice catch, this seems to work all right, yes, although I only had a quick test. All it takes (besides installing Dynamic Cache, of course) is to add this to the end of
virtual_site_theme.module:If you try it and you also find it OK, I'll put it into dev immediately.
Comment #6
Clément commentedHello, I'm sorry but for me it does not work when de cache is enabled.
virtual_site_load_active() return false when it is tested
I just tested this:
Condition OK 1 == display
Condition OK 2 == hidden
Comment #7
djg_tram commentedIt worked for me when I changed it but then stopped swapping the theme, yes. Needs more thought, unfortunately.
Comment #8
adamps commentedI don't have enough knowledge to say if there is a way to get Drupal cache to be aware of caching separately for different Virtual Sites. Possibly it is already able to do it for different languages and the same technique could be used.
However I can suggest a workaround - it's quite common to see websites with a different URL for mobile, which would presumably solve your problem. Or, now 3 years on from the original issue, I'd say responsive themes are gradually taking over from separate mobile sites.
I will try to write some documentation for this, that's probably all we can do.
Comment #9
adamps commentedIn later email discussion djg_tram pointed out another module that could help, ThemeKey https://www.drupal.org/project/themekey which claims: