Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Template switch

Template switch

Hi Stephen!
My question: Is it possible to switch template without quitting the browser in this Chameleon?
This video link shows switching template but he quits the browser.


Can i do it without quitting?
Any idea?
Thanks!

joe30
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Template switch

Hi,

the template was originally changed from the DEFAULT to the NEW template, just by following a link that had "landing=1" in it. The user didn't have to quit the browser for that to happen.

If you want the user to be able to switch back to the original template again, that's easy to set up using an additional rule.

In shorthand, you could describe the rules like this:

Rule 1:
- detect "landing=1". If found, set session variable A. Continue to next rule.

Rule 2:
- detect "landing=2". If found, UNset session variable A. Continue to next rule.

Rule 3:
- detect session variable A. If found, switch to alternative template.

Using this system you can then have 2 hyperlinks on your page:

example.com/homepage?landing=1  -- if people click on this they get the alternative template
example.com/homepage?landing=2  -- if people click on this they revert to the default template.

Simple!

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Template switch

Hi Stephen!
I thank you very much for your reply!
I have another question if you don't mind.
Is it possible, to solve that if you read an article end you, switch template, you stay on this article? (because now you get back to hompage, as you show: example.com/homepage?landing=2)
Thank you for your help.

joe30
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Template switch

One way you can do it is to make your hyperlinks contain only the query string, e.g

<a href="?landing=1">template 1</a>
<a href="?landing=2">template 2</a>

However this will knock off any previous query string that was on the URL. If you are using SEF URLs then you'll be ok in most cases except maybe where there's pagination going on.

Do you think that will work for you? There are some other tricks that could be tried, but that's the easiest one.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Template switch

Hi Stephen!
Thank you for your reply!!!
I did this:
In Chameleon:
Rule 1:
Environment:
Page URL: contains -> landing=1
SUCCEED Actions:
Cookies/sess vars 1: Set session variable A
Process next rule in chain: yes

Rule 2:
Environment:
Page URL: contains -> landing=2
SUCCEED Actions:
Cookies/sess vars 1: Remove session variable A
Process next rule in chain: yes

Rule 3:
Quick Rules:
Cookie/Session variable: Session variable A
SUCCEED Actions:
Set TemplateStyle: example template
Process next rule in chain: yes

I created a new module (Custom HTML)
It contains(Hyperlink):
<p><a href="?landing=1">template 1</a><a href="?landing=2">template 2</a>
</p>

Front Pege: Template Switcher
template 1 --> example.com/home?landing=1    -->example template
template 2:-->example.com/home?landing=2    -->default template
It works, but when I switch temlate, i get back to homepage. (i tried to enable and disable SEF URLs)
Could you show me Onether trick?
Im Sorry the many question! sad
Thank you!

joe30
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Template switch

Hi Joe,

I'm surprised that this didn't work for you with SEF URLs turned on. But there is another way :-)

Chameleon has some substitution tags built in to the URL redirection system, and you can use this together with find-and-replace to put these onto your page.

So:
- you put the following into your module (tokens exactly as written):
<p><a href="{LANDING1PAGE}">template 1</a><a href="{LANDING2PAGE}">template 2</a>

- you make a rule that calculates the new URL based on the current one, then does a find-and-replace on the page to replace {LANDING1PAGE} and {LANDING2PAGE} with the correct URLs.

Here's how to do that:
1 - make a new rule (and you'll need to make this the 1st rule in the chain)
2 - in the PHP block in the SUCCEED action, put the following:

$url = '{scheme}hmm/{host}{:port}{path}?{query}';
global $redirect_url;
$redirect_url = comChameleonHelper::redirect_url_substitutions( null, null, $url );
// get rid of existing landing indicators from the query string
$redirect_url = str_replace("&landing=1","",$redirect_url);
$redirect_url = str_replace("&landing=2","",$redirect_url);

3 - in the search and replace boxes in the SUCCEED action, place the following:

search 1: {LANDING1PAGE}
replace 1: {global:redirect_url}&landing=1
search 1: {LANDING2PAGE}
replace 1: {global:redirect_url}&landing=2

(restrict both to <body> only)

4 - ensure that the succeed action is set to "process next rule in chain"

That should do it :-)

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Template switch

Another way to do it is if you are handy with Javascript. Using JS you could directly (client side) set a cookie that can be picked up in Chameleon, then you use that cookie instead of the session variables (i.e. permanent cookie "A" rather than session variable "A").

Permanent cookie "A" is actually a cookie with name MT1 and value 1. To remove "permanent cookie A" you just delete/expire that cookie.

After setting the cookie, you use JS to force a page refresh.

Here are some JS snippets that you might find useful to put together into a solution:

set a cookie:

document.cookie="MT1=1";

delete a cookie:

document.cookie="MT1=1; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

refresh the page:

location.reload();

I'll leave it up to you to code that into your hyperlinks.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Template switch

Hi Stephen,
I found out why it does not work for me sad  sad  sad
I have the old version (v.2.36, not support, such as:  Added "Find and Replace" actions )
Thank you very much for your patience and help!

joe30
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Template switch

Hi Joe,

you know you can download the most recent version, as long as you already purchased the Joomla 1.7/2.5/3.x version? ThT will give you all those new features.

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Template switch

metamodguy wrote:

Hi Joe,

you know you can download the most recent version, as long as you already purchased the Joomla 1.7/2.5/3.x version? ThT will give you all those new features.

Cheers,
Stephen

Hi Stephen,
I updated the version.(chameleon v.2.49)
It works what is in #6 comment!
Thank you very much for your help!
Regards
joe

joe30
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
3
User Info:
 
Total Users:
4397
Newest User:
tull687318
Members Online:
0
Guests Online:
212

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked