transfer variables to CSS file

Discussion in 'CSS' started by gclass, Dec 24, 2009.

  1. #1
    Hello,

    I would like to transfer variables to CSS files to allow ease of use when modifying.

    ie:
    stylesheet.css:
    margin:$margin;
    Code (markup):
    config.php
    $margin = "20px";
    Code (markup):
    so the value in CSS file will be taken from config file,

    Thx
     
    gclass, Dec 24, 2009 IP
  2. chandan123

    chandan123 Prominent Member

    Messages:
    11,586
    Likes Received:
    578
    Best Answers:
    0
    Trophy Points:
    360
    #2
    margin=<?php echo $margin ; ?> :)
     
    chandan123, Dec 24, 2009 IP
  3. gclass

    gclass Active Member

    Messages:
    337
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #3
    hi chandan,
    how to I include the config.php in the CSS file?
    also, the line you wrote is not valid in Dreamweaver, should it be:

    margin:<?php echo $margin ; ?>;

    Thx
     
    gclass, Dec 24, 2009 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Ok, I've seen some people trying to defeat the entire point of using CSS before, but this one ranks right up there. Good way to prevent it from caching.

    I'm not sure exactly what you are trying to accomplish with that, but I suspect you either are trying to put in an external file one of the RARE cases that **** should be in the markup, or have completely over-thought the solution to your problem.

    Do you have an example of what it is you are actually trying to do?
     
    deathshadow, Dec 27, 2009 IP
  5. gclass

    gclass Active Member

    Messages:
    337
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #5
    Hi Deathshadow,
    I would like to have few PHP pages with CSS file and one file to deal with for predefined modifications.

    for example: will have 4 PHP pages, one CSS file and one CONFIG.PHP file.
    in the config.php file I will be able to change and set variables that will be used in the PHP files and the CSS file, this way I will be able to edit one file for all the changes I need. (not me actually, but my user).

    Thx
     
    gclass, Dec 27, 2009 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Honestly, I'd make the CSS file static, and any values you need to change send in the markup... Which is one of the FEW cases I'd say to put presentation in the markup.

    The reason being if you send the CSS from a php file, the CSS won't cache, which is one of the reasons to USE external CSS in the first place.

    Another approach I'd consider is either giving your php permission to write to a static .css file, or connecting to yourself via FTP to write it that way...

    at the end of the day, what you really want is that CSS file to be static for 99.99% of users so it can cache, otherwise you've defeated the point of HAVING CSS in an external file, and might as well go back to using HTML 3.2 without it.
     
    deathshadow, Dec 28, 2009 IP
  7. gclass

    gclass Active Member

    Messages:
    337
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #7
    ok, thx a lot.
    I will put the code I want to change inside PHP files and all the rest in CSS.

    Cheers
     
    gclass, Dec 28, 2009 IP