View Full Version : importing css paged on $_GET or similar?

05-07-2008, 11:03 PM
Right now I have in the header section of a template file a few lines of code to include various css style sheets, such as:

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

I'm reading up a little on using @import, and I'm wondering how you would go about importing various style sheets based on what page is currently loaded. I'm was wondering if its possible to $_GET to identify a page name, and then import the necessary style sheets defined for that page?

I hope to try this in a few hours, but the mrs. is demanding some much needed attention at the moment:)

05-07-2008, 11:27 PM
Um... yeah, it's possible. Just do like what you said in your post. I'm not sure what the issue is?

05-08-2008, 01:59 AM
Thanks for the help. I'm working on trying to understand the best way to accomplish it. I created the following, but will not work when I add the 'page' to the url

//File: css.php

header('Content-Type: text/css');

//Import Base CSS Files

$page = 'browser';
//$page = $_GET['page']; <-- Not working when add ?page=browser to url?

if($page == 'browser'){
} else {

and in my main file, I simply added the following to the head

<style type='text/css' media='all'>
@import './css.php';

05-08-2008, 10:29 PM
Well, I'm much closer, but still have an issue with it. I've created a css.php file as shown below:

The issue now appears to be that the default css is not being loaded when there is no ?p in the url. If I include ?p=browser, the default css loads. But shouldn't the default css load even without the ?p in the url? I really don't want to have to list every page/file with an array() to have the default css load.

//Set Default CSS Files
$default = array('base.css', 'tooltips.css');

//Set Optionaal CSS Files
case 'browser':
$optional = array();
case 'game':
//Get the Board, Units, and Flag CSS
$optional = array('game.css');
case 'default':
$optional = array('none.css');
} else {
$optional = array('none.css');

$css = array_merge($default, $optional);

//Combine Default and CSS Arrays
//Out all the CSS

foreach($css as $value){
echo ("<link rel=\"stylesheet\" type=\"text/css\" href=\"./css/{$value}\" /> \n");