Creating a button to switch standard page context


(Oliver Kass) #1

Matrix Version:5.4.1.3

Hi folks,

Looking to add a button to a site that would enable a user to manually switch the language on a page.

I’m a bit stuck on how to achieve this. Was thinking of using a Get Variable for the Context Detection setup but not 100% how to actually set it all up. Would like to append the page url with something like ?language=languagetype whenever the context was in view.

Any ideas?

Oli


(Bart Banda) #2

Do you have a different URL for the different context? If not, you might run into problems when it comes to caching as Matrix or your proxy will cache one context for everyone in that case.

Ideally, if you are running cache and contexts, the best way is to apply a completely separate URL and target the context based on that. WOuld that work for you?


(Douglas (@finnatic at @waikato)) #3

We’re using a simple button currently, passing a parameter - example:

https://www.waikato.ac.nz/study/subjects/te-tohu-paetahi?lang=mi

on the contexts screen we have the alternate contexts setup to see if the GET variable lang is whatever we’re checking for.


(Oliver Kass) #4

Thanks for this. It’s exactly what I was trying to achieve. How do you have the alternate context setup? i.e. what do you have in the condition details fields?

I’ve tried a few things but still can’t get it to display the context on the front end…clearly missing something


(Oliver Kass) #5

OK, thanks Bart. I’m gonna try option 1 first but if we run into problems I’ll take a look at this. We only need context on a few pages.


(Douglas (@finnatic at @waikato)) #6

What we have is:

"All of the following 1 condition(s) must be met:

  • The GET variable lang is “mi” (Case sensitive)"

or in the edit section -

  • Condition Type - GET Variable
  • Condition Details - Match if the GET variable named lang does exactly match mi - with case sensitive ticked.

NB: I think we have front end (Varnish) caching disabled for these pages, not 100% sure.


(Oliver Kass) #7

Hi Bart,

So I’ve gone ahead and got this work with a get variable. Caching appears to be ok although I’ve found an issue where it’s caching the content if you view in Edit and then go back to the content on the site - logging out fixes it.

Any ideas why this might be? Don’t get the same issue with admin or viewing the content as a public user…

Oli


(Bart Banda) #8

Sounds like you are simply just viewing the logged in version of the content at that point before you log out?


(Oliver Kass) #9

Could be, not sure I fully understand what the “logged in version” is though?

Having it cached when logged in is potentially problematic for editors as it means they can’t switch back and forth when editing…

Am I missing something?


(Bart Banda) #10

Are the editors editing pages in Safe Edit at all, or are they editing page directly live?

Also, what caching mechanisms do you have in place? Matrix cache, Squid, or Edge?

Probably should have asked those earlier.

With Matrix cache, you can have group caching enabled, meaning that all users in the same group or with the same permission get the same cache entry. Which could explain the difference you see when you log out. But also if the editors are editing in Safe Edit, seeing the Safe Edit version when they view the page on the frontend, but then see different content as soon as they log out, would also explain it.


(Oliver Kass) #11

Editors are editing in under construction at the moment Bart.

It’s behaving the same for me as a sys admin. i.e. I go to the unpublished page on the frontend and it works fine even though I need to login via admin to view.

As soon as I login via Edit the page gets stuck in a single context on the frontend.

I’ve disabled Matrix Cache for the section of the site and we are using Edge.


(Bart Banda) #12

Oh right, so it’s the context that you are editing in and then when you exist Edit+ you might be viewing a different context?


(Oliver Kass) #13

Whatever context you were last viewing in edit seems to cache on the frontend.

So for example if you login and switch to context b, then go to the page itself it won’t switch to context a via the page button. Just remains stuck in b.

If you then go to the edit screen and switch to context a, it gets stuck in context a again.

Logging out seems to resolve it.


(Bart Banda) #14

Yea I think that’s expected if you are logged in as an editor. Mainly so that you don’t get confused that you just edited something in context B, view a page on the frontend and suddenly see context A. But I guess it also depends on the context setup you’ve got in the Context Configuration screen and which URLs you’ve got contexts applied to on the Site asset?


(Oliver Kass) #15

We’re only appending the url via a context get variable and the button on the front end allows users to switch between the url and url?lang=x

It just seems odd that this button would no longer work for editors and that the issue doesn’t seem to crop up for backend users.


(Bart Banda) #16

Oh right, if you are switching context with just a URL query it will not play nice with caching because as soon as you click on a different link you will lose the ?lang=x part and get the current context cached on the next URL for all users.

If you are using contexts for different languages and need to have caching enabled, it’s best to use different URLs for each context.


(Oliver Kass) #17

Makes sense to a certain extent but not getting the issue with live pages and logged out.

When I went for the url option I was getting similar issues with the added problem of the urls staying in context as a user travelled through the site - we only have a few pages that need a context so this wouldn’t make sense.

Think I might have to raise a ticket for it and see what the chat is.


(Bart Banda) #18

Yea that might be the best way. Will be interesting to see what they say and if they figure out the issue.