SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    database driven style sheet

    I'd like to be able to manipulate style settings in a .css file using a PHP/MySQL database driven Content Management System. Is such a thing possible? I wouldn't think I would be able to run a query, fetch variables, etc. on a .css file like I can on a .php file.

    Code:
    html { 
            background-color : <?php echo $bgcolor;?> ;
            color: <?php echo $color;?> ;
        }
    Yet I'd love to somehow control my style sheet settings via my CMS. Any thoughts on how to do this?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    i'm pretty sure it can be done, but as i don't write php, i can't tell you how

    you either have to set the web server to parse .css files along with .php files, or set up a "404 handler" which takes over when the file isn't actually there (this is what i do on my web site with coldfusion)

    yes you can pull from a database to generate the css file
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Rudy's right. It can be done, but you'd probably have to declare a variable for every selector you're going to use in the stylesheet, then match it against the properties and values in those selectors.

    Sounds like a lot of hard work to me though. I'd prefer to just write it in the stylesheet and be done with it.

    (Though I do see the value of doing this for people who don't have experience with CSS.)

  4. #4
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys. It just occurred to me that instead of fiddling around making a .css file parse PHP, I can just set up my styles within a .php include to embed them in the head area of my top.php file. Much as I like using an external .css file, I think this is a simpler solution. Yes?
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  5. #5
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I set up an include within the head section of my top.php file thus:
    PHP Code:
    <?php require_once("styles_basic_default.inc.php"); ?>
    And set up the include styles_basic_default.inc.php with an include of its own to query the database thus:
    PHP Code:
    <?php require_once "site_info.php";//queries the database and fetches variables for values to plug into the selector properties thus:
    html 
        
    background-color : <?php echo $body_bg_clr;?>
        }
    Works great!
    Paul C.
    ClickBasics
    http://www.clickbasics.com

  6. #6
    Web Enthusiast
    Join Date
    Jul 2000
    Location
    Western Massachusetts, USA
    Posts
    1,389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually the include was:
    PHP Code:
    <?php require_once "site_info.php";

    <
    style type="text/css">
    <!--
    html 
        
    text-align center;
        
    background-color : <?php echo $body_bg_clr;?>
        color: #000000;
        }
    etc...
     -->
    </style>
    Paul C.
    ClickBasics
    http://www.clickbasics.com


Bookmarks

Posting Permissions

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