Server Variable Condition


#1
Hello everyone
 
I'm trying to setup a Server Variable Condition to display alternate content based on a cookie. All seems very straight forward, but I'm obviously doing something wrong (v5.3.4.0 ). Cheers for any wisdom.
 
Settings on Conditions screen:
[sharedmedia=core:attachments:819]

 

 

Asset contents:

%globals_cookie_homepage-cookie%

<hr/>

%begin_Cookie_detect:782719%
Cookie!
%else_Cookie_detect:782719%
No Cookie
%end_Cookie_detect:782719%

Prints on front end:

 

staff-home

_________________

 

No Cookie

 

  ServerVarConds.PNG (7.66 KB)


(Marcus Fong) #2

Are you sure “Server Variable” is the best choice here?

It looks to me like you’re trying to specify the Matrix keyword for the cookie you want to match against, in which case I would’ve thought a “Keyword Regexp” condition would be a better fit.


("%globals_cookie_homepage-cookie%" is the Matrix global keyword replacement for the “homepage-cookie” cookie, whereas the relevant server variable would be HTTP_COOKIE, which would give you the raw Cookie: HTTP header as a single string containing all the cookies sent by the browser.)


#3

Cheers for the information & support on this Marcus!

 

[Solved]

 

I completely overlooked the 'Keyword Regexp' option for this [head slap]


(Bart Banda) #4

Do you even need the condition? Can you just use the global keyword conditions for it?

%begin_globals_cookie_homepage-cookie^eq:staff-home:PRINT:%
  PRINT
%else_globals%
  DONT PRINT
%end_globals%

#5

No, Condition not required. I think global keywords are the go. Thank you Bart!


#6

You're going to hate me, but I am going to add a Caching issue into the mix...

 

Barts code works peachy, but only combined with _nocache or _rechache URL suffixes.

I have cache="0" on my body design area and use the below meta tags with no avail:

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
  • Only adding _nocache shows expected content or
  • using _recache and subsequent removal of _recache suffix

I've never had so much 'fun' with caching, so will be grateful for any (further) help.


(Marcus Fong) #7

Those meta tags are only useful if your end user’s browser cache is the problem. That doesn’t seem likely if _recache is doing something to help. It sounds to me like you’ve got a Matrix cache issue, which would be fairly normal after adding conditional logic to your content.

I’d suggest using a Root Node cache exception in the Matrix Cache Manager to disable Matrix cache for the relevant page. Your performance will degrade, but that’s the price you pay for having “smart” pages.


(If you really want to keep the performance loss to a minimum, then you could redesign things to put the conditional content on its own URL and fetch it into the page with AJAX. That way you can still cache most of the page, while still leaving the conditional content uncached - but there is a tradeoff in terms of accessibility.)


#8

Thanks Marcus! Cache exceptions did the trick (to an extent).

 

We observed that it doesn't work in ie11 when a page is set as the browser's homepage. A regular browser refresh will honour the condition logic but a new session either ignores the condition or doesn't read the cookie for some reason.

 

Ever come across this before?


(Marcus Fong) #9

No, I haven't seen or heard of anything like that. The key point to confirm there would be whether or not IE11 is sending the cookie.


#10

Cheers for the quick response. Yup an odd one, such is the network environment we operate in.