Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    importing css paged on $_GET or similar?

    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

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Um... yeah, it's possible. Just do like what you said in your post. I'm not sure what the issue is?

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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

    PHP Code:
    //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

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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    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.

    PHP Code:
    //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");



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •