This topic is locked
[SOLVED]

 Dynamic Stylesheet assignment

1/19/2011 5:01:53 PM
PHPRunner General questions
F
fmbma author

Is there an example where a stylesheet could be loaded dynamically based on a field in a user table? For example, if I develop different stylesheets - red.css, green.css, blue.css and add a field in the user table to allow the user to select their preferred style. Could this be loaded globally, or even on a page by page basis?
thanks

J
Jane 1/20/2011

Hi,
to load stylesheet dynamically replace this code on the Visual Editor tab:

<link REL="stylesheet" href="include/style.css" type="text/css">

with this one:

<link REL="stylesheet" href="include/{$custom_style}" type="text/css">



Then assign value to $custom_style variable in the Before display event on the Eventstab:

$xt->assign("custom_style","style.css");
F
fmbma author 1/20/2011



Hi,
to load stylesheet dynamically replace this code on the Visual Editor tab:

<link REL="stylesheet" href="include/style.css" type="text/css">

with this one:

<link REL="stylesheet" href="include/{$custom_style}" type="text/css">



Then assign value to $custom_style variable in the Before display event on the Eventstab:

$xt->assign("custom_style","style.css");



Thanks, that worked really well. For those who want to try this - I named different styles like styleGray.css, styleBlue.css, styleRed.css, etc.
I added a field called UserTheme in the User table. It is populated with the available colors, Gray, Blue, Red, etc.
Then in the successful Login event, I set a session variable:

$_SESSION["UserTheme"] = $data["UserTheme"];


In the Before Display event, I modified Jane's code as follows:

$xt->assign("custom_style","style".$_SESSION["UserTheme"].".css");


Jane, is there anyway this could be done globally without modifying every page?