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.

 

Keep current template style active

Keep current template style active

Hello I am looking for a way to make the assigned template to a page stay active, so for example if I assign template atomic to a page and this is the first page that someone visits. This is then the template that stays active for their session. Is there a way to do this without a URL parameter, because there is going to be quite a lot of templates on my site with each page effectively being a whitelabel template. The problem being when they used component pages like register the template defaults back to the default template.

Many thanks
David

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

Re: Keep current template style active

Yes, you can do this without a URL parameter. There's a video (see the tutorial videos) that shows you how to do this with a URL parameter, but the technique is almost identical when you detect the landing page via any other method.

e.g. if you have a page "/article1" then you can detect that page and use it to set the session variable or cookie. You can detect it via URL or via menu item - whatever you like.

The bigger issue for you may be if you need more than Chameleon's 4 built-in session variables or cookies. You need one per template that you want memorised. To use more than this you just need to use a little PHP in the condition and/or actions.

While you are getting it set up though I would suggest that you stick with the provided session variables or cookies, just so you can get an understanding of how it works. Then get back to me and I'll hunt down the sample code for using arbitrary numbers of cookies or session variables. Or, you can search through the forum as it's all in here!

The basic idea with doing landing pages and remembering the template for the rest of the session is this:

(based on 3 landing pages)

Rule 1: detect sess variable A. In the action, trigger template 1 then quit the rule chain
Rule 2: detect sess variable B. In the action, trigger template 2 then quit the rule chain
Rule 3: detect sess variable C. In the action, trigger template 3 then quit the rule chain
Rule 4: detect landing page 1. In the action, reset all sess variables, then set sess variable A and set template 1.
Rule 5: detect landing page 2. In the action, reset all sess variables, then set sess variable B and set template 2.
Rule 6: detect landing page 3. In the action, reset all sess variables, then set sess variable C and set template 3.

See how it works? On the 1st page you visit, rules 1-3 won't detect a previous session variable, but rules 4-6 may do. If detected, the session variable is set for the next page, and the template is set for the current page.
On the next visit, one of rules 1-3 will cause the template to be set according to the 1st page you hit.

Best regards,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Keep current template style active

Hi,

Thank you for the response I have set this up using landing page parameters just as you described in your videos.

Now I am in need of expanding the rule further as you described as the site can potentially have 100's of pages each with a unique template that needs to be remembered for the session length. Can you possibly help me out with the code, It would be fantastic if it could be a site wide parameter something that will detect the template set by the menu assignment and then keep that. But I am more than expecting I will have to set a new rule for each page.

Any further advice would be appreciated.

Many Thanks
David

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

Re: Keep current template style active

Hi David,

For the following technique, I am going to use this scenario:

- landing page is /landing?pid=XXX where XXX is a number that will determine the template to be used.
- the template needs to be remembered for the rest of the session.

In this case we are going to use just 1 rule. Just 1!

In the PHP box in the main rule (not the succeed or fail actions), use the following:

Code:

$my_template = @$_SESSION['CHAMELEON_TEMPLATE'];


// if we remembered the style id in the session, use it.
if ($my_template) return $my_template . ":continue";

// otherwise, abort if we are not on the landing page
if ($core_genius->check("url not contains mysite.com/landing?pid=")) return false;
$pid = JRequest::getInt("pid");

// make a mapping array like this that maps the pid number used, to the
// template style ID. You can find this ID in the list of "available template styles"
// when you edit a Chameleon rule. The PID is on the left, and the template style
// id is on the right.
$pid_to_template = array(
  1=>44,
  2=>45,
  3=>46,
  4=>57,
  5=>102,
  6=>106,
// add as many lines as you need.
);
$new_style = @$pid_to_template[$pid];
if ($new_style) {
  $_SESSION['CHAMELEON_TEMPLATE'] = $new_style;
  return $new_style . ":continue";
}

Using this technique, all you have to do is maintain the array of associations.

There is also no need to use the succeed/fail actions. You can do if you wish, as I've set it up so that if the template is changed it will run the Succeed action, so you could use that to make other changes on the site. If the template is not changed, the Fail action will be run.

I trust that helps,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Keep current template style active

Hello,

I just wanted to log back in to say thank you very much I have just integrated this today using the above method and it works really well. I have done it so that the pid to template array is just 1-1 so  it will work all the way up to the first 1000 templates.

Thank you so much for your help this component is fantastic.

David

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

Re: Keep current template style active

Hi David,

thanks for reporting back - I am very pleased it's working so well for you.

Best regards,
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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Keep current template style active

Hello,

I have one more question, Is there anywhere that allows me to choose how long the cookie session stays active with this rule? so if people go between different links with different ?pid parameters at the end it will almost always work rather than remembering the last set variable?

David

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

Re: Keep current template style active

Hi David,

the session length is controlled in Joomla configuration. If you instead would prefer to use cookies, then the code above can be modified to use cookies instead of the session.

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
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Keep current template style active

Hi,

Thank you I must have confused myself because I did know that and I had already adjusted the session time once before!.

Thanks again
David

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

Re: Keep current template style active

[PROBLEM RESOLVED]

thomasdja
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10727
Newest User:
solza2
Members Online:
0
Guests Online:
154

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