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.

 

Assistance for a beginner please.. I might be stretching boundaries..

Assistance for a beginner please.. I might be stretching boundaries..

Hi there,  I am looking for some assistance in building a set of rules for Chameleon.  I am completely confused at the moment but hope that with a little help I can get underway   I got things working partially a while ago but left it in the too hard basket and continued with the rest of the site, but I am now back to it.

So here is the scenario, and how I THINK I need to approach it.

I have one main site mainsite.com, and I want to create a set of ‘sub’ sites, for want of a better word - being mainsite.com/city1 , mainsite.com/city2, mainsite.com/city3 etc. with a different template style, a different landing/home page (a specific Joomla article), and a different menu ( it’s too complicated to publish and unpublished menu items I think )

I have been through the tutorials, and I have managed to get things working for one instance  using session variables A B etc…  but I actually have 13 different ‘sub’ sites (and more to come in the future.)   After reading the forums, I read that I could set cookies (which would work) using PHP, unfortunately my PHP skills are not great, and from reading the documentation and forums just got me more confused (sorry).

I have created a rule chain, to detect if the ‘city’ name is in the URL. 

My SUCCED action set to Run PHP as :

Rule 1

Code:

setcookie ("location", “city1”);

process next rule

Rule 2

Code:

setcookie ("location", “city1”);

setcookie ("location", “city2”);
process next rule

Then in a rule lower down, I want to check the cookie and set success actions… I found code in the forums and modified as I thought it MIGHT be, but I am SURE this is where I am going wrong.

Code:

$location = "nocity"; // this is to effectively set blank I think

$location = JRequest::getString($location, 0, 'cookie');
if ($location = "city1") return true;

When I publish this rule, I get a 404 on domain root / homepage .. when unpublished the site works, but obviously there is no template change…

Can anyone please point me in the right direction, give me hints on what I am doing wrong?

I am sure I will have more questions as I get down the track a little, but this will hopefully get me started.

Many thanks in advance.

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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Hi,

You're really on the right track with what you have done so far. I will help you with the details.

1 - using 2 parameters in the setcookie means that the cookie expires at the end of the session. I assume that's what you want. If you want the cookie to last for longer, you need to add a 3rd parameter like this:

setcookie("location", $value, time()+2*60*60*24);  /* expire in 2 days */

2 - for your detection code, you need to make some changes. Try this:

$location = JRequest::getString('location', 0, 'cookie');
if ($location == "city1") return true; // remember the double == when testing for equality!


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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Hi Stephen.  Thanks so much for getting back to me.

I spent a little bit of time on the forums, and the PHP manual wink and I am now getting somewhere.  I don't think its exactly where I want to be... but I'm moving at least.

I am having one specific problem that if I clear up might fix some others, or at least make them easier to diagnose.

Some information that I realised I didn’t provide earlier in case it helps… I am running J!2.58, PHP 5.3.15, and my template is “Black and White” from Gavick.  I currently have Chameleon debig turned on.

So, I am setting a cookie when a word (e.g. 'albury' ) is detected in the url.  then as I mentioned before, lower down after all the URL checks I am reading the cookie and setting a template variation.

When I click on a link within the site, or if I directly enter the site with www.site.com/albury the new template is not loaded.

Debug says that the rule checking the URL is succeeding and the PHP to set the cookie is run, but then lower down the check for 'albury' cookie fails and the template is not changed.

HOWEVER, if I then refresh the have.. it load the new template!

Is this something that you might have seen before, and do you have anything I might try?


Just in case it helps ( and just ignore for now if now ) I have detailed the rules, order and PHP I have used below.

Rule 1 – Aim -> Check if the MAIN home page is being displayed or has been selected (through the top menu or main logo click), by checking features then delete the ‘location’ cookie.

Condition - Check for Page Type ‘Featured”
Success -> Run PHP + set default template -> Process next

Code:


setcookie ("location", "", time() - 3600);  // delete cookie - location

Rule 2 – Aim -> check if URL contains ‘albury’ -> if true -> set cookie ‘location’ to ‘albury’

Condition - Check Page URL –> contains = albury
Success -> Run PHP -> Process next

Code:


$city = 'albury';
setcookie ("location", $city );  // expire with session

Rule 3  – Aim -> check if URL contains ‘bairnsdale’ -> if true -> set cookie ‘location’ to ‘bairnsdale’

Condition - Check Page URL –> contains = albury
Success -> Run PHP -> Process next-> Process next

Code:


$city = 'bairnsdale';
setcookie ("location", $city );  // expire with session

Rule 4 – Aim -> Check to see if cookie ‘location’ is ‘albury’ -> if true -> set albury template

Condition – PHP to check cookie -> if albury
Success -> Set Template Style = Albury ( ID=13 ) -> Process next

Code:


$city = NULL;
$city = JRequest::getString('location', 0, 'cookie');
if ($city == "albury") return true;

Default PHP return value = false

Rule 5 – Check to see if cookie ‘location’ is ‘bairnsdale’-> if true -> set bairnsdale template

Condition – PHP to check cookie -> if Bairnsdale
Success -> Set Template Style = Bairnsdale ( ID=14 ) -> Process next

Code:


$location = NULL;
$location = JRequest::getString('location', 0, 'cookie');
if ($location == "bairnsdale") return true;

Default PHP return value = false


If you can offer any through of why the refresh might be required, it would be greatly appreciated!  I have looked at a couple of multi site options to acheive what I need, but I really think Chameleon can do the job I need and keep thing FAR simpler!  If you would like to have a look at the site, I would be happy to PM or email you the direct site link.

I realise my knowledge might not be up to scratch here and if you feel things are getting out of 'support' territory, I would be happy to to discuss options for your assistance.

Thanks again for the help you have already provided, and even for what I have been able to see so far, a fantastic tool.

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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Just a quick update.. after more reading.  System cache plugin is disabled ( as is Gavick cache which I turned off for other reasons ) and all cache options I can find on the site are disabled.

I played with the rules and separated the 'home page' (Rule 1 above) into two where I checked for the front page, set the location cookie to 'home' rather than deleting it and then read the cookie to set things back to the home page.

I did some reading and thought I would try using JRequest::setvar to set the cookies ( just to see if it made a difference)

I tried changing the cookie name to 'glocation' just in case location was reserved / used by something else...

I changed the riles to use return id:continue - instead of the dropdown selector to see if this made a difference.

And finally, I actually added  the template selection from the dropdown to the 'check location' rules to see if trying to trigger it twice made a difference.

From all this testing it still requires a page refresh to change the template... so I think something is up smile

Any thoughts appreciated.

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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Hi status101,

thank you for your comprehensive description of the issues. I wish everyone would be so meticulous! It makes the support job a lot easier.

I just did some testing, and I see that if you use setcookie, then you can't pick up the result on the same "page" unless you use JRequest::setVar.

So, as well as setting the cookie with setcookie, also set it like this:


$city = 'bairnsdale';
setcookie ("location", $city );  // expire with session
JRequest::setVar("location",$city,"cookie");

Then according to my testing you can pick it up later in the page load with JRequest::getVar("location",0,"cookie");

Can you try that and let me know if it solves the problem?

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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Hi Stephen, THANK YOU!

Not sure anyone has every used the word meticulous for me before smile but it always helps me to lay things out fully especially when dealing with some sort of logic chain.

So I have added the double set cookie via both setcookie and JRequest, and changed the cookie detection to getVar rather then getString just for consistency with your testing.  Now the respective template is being loaded immediately which is fantastic.

I am seeing another strange behavior now that I think is linked to the 'contains' detection when a certain component is used to generate the link - something called 'content map' - but its a little hard to describe the problem at the moment so I am going to do some more testing and see what I can work it out.

Also, in case anyone else looks at this post - To tidy things up a little and make it easier to add more options later, I have combined the multiple cookie detection / 'set template' rules into a single PHP rule and it seems to work well.

Code:


$city = NULL;
$city = JRequest::getVar("glocation", 0, "cookie");

if ($city == "albury"){
    return "13:continue";}
elseif ($city == "bairnsdale"){
    return "14:continue";}
elseif ($city == "home"){
    return "11:continue";}

(Stephen please correct me if I have done something silly : )

Anyway, thank you again for your assistance with this!  I really appreciate you sticking with me and can not speak highly enough of the level of service you provide for a very powerful and useful tool!

I'm sure I will have more questions as I try and do more with Chameleon but for now I have to go build a bunch more rules and template variations smile

Regards

Michael

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

Re: Assistance for a beginner please.. I might be stretching boundaries..

Hi Michael,

thanks for reporting back - it's great this is working for you now. Just 1 comment about your PHP above: you don't need the 1st line setting $city to null. It will get set in the next statement. Other than that, perfect. You're really getting the hang of it. Fun, isn't it?!

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

Board Info

Board Stats:
 
Total Topics:
1675
Total Polls:
6
Total Posts:
5917
Posts this week:
6
User Info:
 
Total Users:
11577
Newest User:
owens65784
Members Online:
0
Guests Online:
232

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