...

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



ptmuldoon
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:)

Fumigator
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?

ptmuldoon
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'){
include('./main.css');
} else {
include('./game.css');
}

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



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

ptmuldoon
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
if(isset($_GET['p']))
{
switch($_GET['p'])
{
case 'browser':
$optional = array();
break;
case 'game':
//Get the Board, Units, and Flag CSS
$optional = array('game.css');
break;
case 'default':
$optional = array('none.css');
break;
}
} 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");
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum