SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question configuring a stylesheet?

    hello

    in the process of making a set of web tools and i need to make the whole thing as flexible as possible to allow fast migration from server to server and also to allow anyone who installs it to easily change anything from one or two configuration files.

    now all the sites done in php so for the most part this is easily achievable, however i am wondering about my global css file? i know its possible to change stylesheets using javascript where the user can click a button and say change the font size, but what i want to do is the same yet using php to echo the values in the configuration file into the css file? if you get my meaning?

    is this possible in any way directly in the css file? i know i can do it if i carry the css on the top of every html page yet thats far from efficent?

    anyone have experience of this

    a+
    gar

  2. #2
    SitePoint Wizard iTec's Avatar
    Join Date
    May 2001
    Location
    Sydney, Australia
    Posts
    2,243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if your trying to do what i think it is you are wanting to do then you can rename stylesheet.css file to stylesheet.php and dynamically generate your global css file.

  3. #3
    SitePoint Enthusiast rreames's Avatar
    Join Date
    Jun 2002
    Location
    Iowa
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An option would be to have a basic global css file and then have other that hange font size, colors, etc. Then you can use a bit of php to replace those files. In the head put something like this:

    Code:
    <style type="text/css">
    <!--
    @import url("/styles/<?php echo 
    (!$sitestyle)?'new-style':$sitestyle ?>.css");
    -->
    </style>
    <link rel="stylesheet" type="text/css" media="screen"
     title="Standard" href="/styles/NN4.css" />
    <link rel="stylesheet" type="text/css" media="print" 
    href="/styles/print.css" />
    Then create the switcher.php:

    Code:
    <?php
    setcookie ('sitestyle', $set, time()+31536000, '/', 'www.yoursite.com', '0');
    header("Location: $HTTP_REFERER");
    ?>
    Then for your switcher choice code on the page use something like:

    Code:
    Size <a href="/styles/switcher.php?set=new-style">Small</a> 
    <a href="/styles/switcher.php?set=new-style2">Medium</a>
    <a href="/styles/switcher.php?set=new-style3">Big</a>
    Hope this helps, I learned this method here.http://www.alistapart.com/stories/phpswitch/

    To see what I did look here: Midwest Energy

    Good luck.
    Apathetic Activist.
    reames.org

  4. #4
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Originally posted by iTec
    if your trying to do what i think it is you are wanting to do then you can rename stylesheet.css file to stylesheet.php and dynamically generate your global css file.
    will this cause any problems with xhtml file validation when i link the css file like so?

    <link rel="stylesheet" href="stylesheet.php"; ?>" type="text/css" />

  5. #5
    SitePoint Wizard iTec's Avatar
    Join Date
    May 2001
    Location
    Sydney, Australia
    Posts
    2,243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Garrett


    will this cause any problems with xhtml file validation when i link the css file like so?

    <link rel="stylesheet" href="stylesheet.php"; ?>" type="text/css" />
    I can't give you a definate yes/no answer, but i am 99.9% sure that you will not have any problems. I was using the same method with ASP and had both my XHTML and CSS validating. The only area where i can think of something going wrong would be in the way minor devices handle the extension, but even then i dont think there would be a problem as all the output is still text/css/html.

  6. #6
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i had been chatting to a work college and we figured together that ether firstly...

    1) this method

    2) or using a .htaccess file to get a .css file to parse as a .php file

    would be the best solutions, so i'm going to try your idea first and see how that works out.

    thanks for the suggestion!!

    a+
    gar

  7. #7
    Phil fillup07's Avatar
    Join Date
    May 2002
    Location
    Jacksonville, FL
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    An alternative if you can't have your .css file as a .php would be to simple use an include on every page instead of (or in addition to) your style sheet. On the include page, you could just use the <style> tags and display the CSS that way. Wouldn't make a difference in download time for the user, I dont think, since they would have to download the CSS file either way, and you can still update the CSS from just one file...

  8. #8
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok i'm back to this problem as i still have to find a solution thats flexible enough. i'll try to explain the problem as best i can....

    my file structure is like so to maximise flexibility....

    ---------------------------

    mypage.php

    |
    contains an include to a configuration file which contains every value thats changable on the site.
    |
    v
    config.php

    |
    in turn this contains includes to a general php file, a javascipt functions file, and a template html page

    ---------------------------

    now all the variables are defined normally (as opposed to using define()) so they are only local but each is an array, for example every value concerning font and text size on a page is all in the same array() so it can be easily accessed.

    now on mypage.php i pull in my template via some functions and in the template i pull in the stylesheet.php via a ....

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

    and all the values are print_r() out on the stylesheet.php. none of the values seem to be present but what i can't figure out is whether this is due to the fact the stylesheet is not included but linked or the fact its two pages down in the hierarchy from the mypage.php.

    ideas anyone? i appreciate its complex but i'm quite stuck on this!

    a+
    gar

  9. #9
    SitePoint Wizard iTec's Avatar
    Join Date
    May 2001
    Location
    Sydney, Australia
    Posts
    2,243
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Garrett
    i can't figure out is whether this is due to the fact the stylesheet is not included but linked or the fact its two pages down in the hierarchy from the mypage.php.
    its because it is linked and not an include, the php is only taking effect in the mypage.php.

    add the config file to your stylesheet.php and it will be more likely to work.

  10. #10
    SitePoint Addict Garrett's Avatar
    Join Date
    Feb 2001
    Location
    England
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have tried that but can't seem to get it working and its near impossible to test because of the fact its a stylesheet!

    a+
    gar


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
  •