Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » Chameleon / ChameleonLite
- » Chameleon
- » Change a PHP Variable [SOLVED]
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
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
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
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";
}
- Index
- » Chameleon / ChameleonLite
- » Chameleon
- » Change a PHP Variable [SOLVED]
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7624
- Newest User:
- borger3298
- Members Online:
- 0
- Guests Online:
- 170
- 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