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.

 

Change a PHP Variable [SOLVED]

Change a PHP Variable [SOLVED]

I have a template that has several seasonal based themes that are controlled by a $theme variable within the template. This controls the name of the CSS file to load as well as what flash header and several other things within the template. I would like to create rules based on the Month & day of the year that will set this variable.  I have the Rules set up and they are working for the dates, but I don't know how to add the proper success action.  I can set a CSS just fine, but I need to set the variable

taftr
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Change a PHP Variable [SOLVED]

UPDATE:

I tried to put

$theme = 'Winter';

in the RUN PHP section... but it doesn't appear to be working

taftr
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Change a PHP Variable [SOLVED]

Second Update...  I did some testing...  and it appears that the "RUN PHP" in the actions section is executed before any of the page loads.   Putting in:

$theme = "Winter";
Echo $theme;

Prints "Winter" at the top of the page, however adding the echo line within the PHP section of the page header shows the variable is null.  so it seems to be something about the variable being set globally.  I have no idea how to overcome this limitation.  I really don't want to make a separate template for every "season" I want to have.   If anyone can tell me what I'm doing wrong, and how I can fix it.  I really would appreciate it

taftr
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Change a PHP Variable [SOLVED]

Hi taftr,

The easiest way to transfer the value from Chameleon into your template is going to be to use a global variable. It's not a purist's way of doing it but it's very effective and will work perfectly well.

I would suggest the following:

1 - in Chameleon, use the following:

global $chameleon_season;
$chameleon_season = "Winter";

2 - in your template, just before the $theme variable is used for the first time, do the following:

global $chameleon_season;
if ($chameleon_season != '') $theme = $chameleon_season;

That should transfer the value from Chameleon into the template, but only when Chameleon has set it. (otherwise it will leave it alone).

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

Re: Change a PHP Variable [SOLVED]

Thanks for getting back to me....    That worked perfectly....   I also found that using DEFINE works also, but I like your method better

define("THEME", "Winter");

Then in the Template

if (THEME != "") {
    $theme = THEME;
} else {
    $theme = "Default";
}

taftr
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
4
User Info:
 
Total Users:
4379
Newest User:
coates7891
Members Online:
2
Guests Online:
248


Forum Legend:

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