TK doesn't switch themes on fresh/first page load even though debug shows matching values.
I have a single rule
system:cookie = Drupal_session_cache_nomobi=s:1:"0"; -> myMobileTheme
Debug shows the following on a first load:
No match: "system:cookie = Drupal_session_cache_nomobi=s:1:"0"; >>> myMobileTheme"
system:cookie
Drupal_session_cache_nomobi=s:1:"0";
If I reload the page, it matches and switches the theme. If I clear domain cookies and reload it then again doesn't match until I reload.
I tried clicking on the cookie value for TK to build my rule but it just creates what I already have there.
f.y.i. I create this cookie at the top of template.php using the 'Session cache' module functions.
Any advice appreciated.
Comments
Comment #1
mkalkbrennerThis is not a bug but the nature of Cookies and HTTP!
A cookie becomes part of every HTTP request after it has been set.
The second problem is that template.php gets included after the theme decision has been taken. So we can't do a workaround here.
One workaround is to create a custom module and to move your code to set a cookie in hook_init().
In Addition to set the cookie you can fake the cookie one time by using this line:
Comment #2
ksavoie CreditAttribution: ksavoie commentedThanks for the reply!
I moved my code from template.php into a module but am still experiencing the same behavior.
Do you see a flaw in my modules logic?
Thanks!
Comment #3
ksavoie CreditAttribution: ksavoie commentedOK, I must be really dense as I am not able to understand how to get at this simple need.
All I want is the ability to switch back and fourth between themes via a URL param.
I keep getting hung up because TK skips altogether properties if they are empty so I cant base a decision on if empty. Thus cant track which theme should be activated via my cookie. Especially troublesome on first site visit when cookie values are not available.
I know that this shouldn't be that hard, what am I just not getting..... :?
Comment #4
ksavoie CreditAttribution: ksavoie commentedComment #5
mkalkbrennerWe already discussed that in the past. The conclusion was that this feature will have a negative impact on performance.
But maybe we should open a new issue for that because the engine changed a lot.
If you provide concrete examples I will help you with the rules.
Comment #6
ksavoie CreditAttribution: ksavoie commentedI was finally able to come up with a config that looks to work.
TK Rules:
system:query_string | = | nomobi=true | my_default_theme
---
system:cookie | = | Drupal_session_cache_nomobi=s:1:"1"; | my_default_theme
---
system:cookie | = | Drupal_session_cache_nomobi=s:1:"0";
+ browscap:ismobiledevice | = | true | my_mobile_theme
---
browscap:ismobiledevice | = | true | my_mobile_theme
Then to manage the cookies I have a custom module with the following
I am still down with this as I would have been done with this issue long ago if I could have queried for 'empty'. : )
Comment #7
mkalkbrennerDuring the work on the 8.x port we recognized again, why a check for "empty" could not work in our engine without modifying (and probably slowing down) the engine itself.
Comment #8
ksavoie CreditAttribution: ksavoie commentedSorry for my ignorance but there is a noticeable performance hit even if a check for empty on that specific parameter only occurs if its rule is part of the rule chain?
Tks.