Topic: passing variables to external css? (Page 1 of 1) |
|
---|---|
Maniac (V) Inmate From: there...no..there..... |
![]() Here is what I am trying to do. I have pages that are loaded from a php include. I need to pass variables to an external style sheet as well. It can be a lot of variables depending on the page. code: switch ($_GET['link']){ case 'page1': $page = "pages/page1.php"; $bodyClass="page1"; $bgColor = "#008000"; break; case 'page2': $page = "pages/page2.php"; $bodyClass="page2"; $bgColor = "#800000"; break; default : $page = "pages/main.php"; $bodyClass = "main"; $bgColor= "#8080FF"; }
code: <? header("Content-type: text/css"); ?> body { background:<?=$_GET['bgColor'];?>; }
code: <div> <a href="index.php?link=page1">Page 1</a><br /> <a href="index.php?link=page2">Page 1</a><br /> <a href="index.php?link=main">Main</a> </div>
code: <a href="index.php?link=page1&bgColor=#800000">Page 1</a><br />
|
Paranoid (IV) Inmate From: Norway |
![]() make sure to pass the parameters in GET to the external stylesheet, i.e: code: <!--here be doctype declaration, head, ... --> <link type='stylesheet' media='screen,printer' href='style.php?link=<? echo $_GET['link']; ?>' /> <!-- here be monsters, script tags, the body and all the malarkey --> Hope that helps |
Lunatic (VI) Inmate From: under the bed |
![]() I think you may be overcomplicating the issue. Is the <body> the only element to be affected? code: body.page1 h1 { ...styles... }
|
Paranoid (IV) Inmate From: Norway |
![]() DL-44: sure, that's the cascading is one of the biggest strength of CSS. Add to that that having a single biiiig stylesheet that can be cached beats having a zillion of smaller not so cachable ( due to the arguments passed in GET ) stylesheets any time. |
Maniac (V) Inmate From: there...no..there..... |
![]() DL-44: The body class is just one that would be affected. There are a bunch more depending on the page. The "About Us" page might have 5 - 6 elements that would be different than the rest, the "Contact Us" page would have maybe 10 (just guessing on the numbers). That is why I just wanted to pass variables to the style sheet. code: body{ margin:0px; padding:0px; }
code: body.page1{ background-color:#8080FF; }
|
Paranoid (IV) Inmate From: Norway |
![]() |
Lunatic (VI) Inmate From: under the bed |
![]() Anything specified in the secondary stylesheet will overide the same specs in the primary. |
Maniac (V) Inmate From: there...no..there..... |
![]() quote:
|
Bipolar (III) Inmate From: midair |
![]() quote:
|
Lunatic (VI) Inmate From: under the bed |
![]() what you need to look at is mod_rewrite |
Bipolar (III) Inmate From: midair |
![]() Thanks DL-44 |
Maniac (V) Inmate From: there...no..there..... |
![]() quote:
|
Bipolar (III) Inmate From: midair |
![]() Thanks CPrompt |
Nervous Wreck (II) Inmate From: |
![]() long sought this information, thank you guys! |
Maniac (V) Inmate From: The Pool Of Life |
![]() |
Maniac (V) Mad Librarian From: Seoul, Korea |
![]() Now that's some prime necroposting there, that is. |