SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic Path in background-image: url() for URL

    Hi:

    I have directory structure for images like

    /themes/images/icon/icon_something.gif

    In my CSS I specify it like
    Code:
    background-image: url(/themes/default/images/icon/icon_confirmation.gif) ;/**/
    I was wondering if there is a way to do this dynamically. i just wanted to make sure that If I change the path to this folder like

    /templates/themes/images/icon/icon_something.gif

    Then it would still work.

    Is there a way to change these paths dynamically in the CSS? like sending it directory path through PHP or something?
    ---------------------------
    Errors = Improved Programming.
    My Site

  2. #2
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should just be able to create a css file with .php extension but then serve it using type="text/css". Never tried it myself but don't see a reason why it wouldn't work

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never Mind. I changed and called it with parameter and it worked

    HTML Code:
    <link href="/css/css.php?tpl_dir={$tpl_dir}" rel="stylesheet" type="text/css" media="all" />
    ALl I have to do in the CSS file is
    Code:
    <?php
    	header('Content-Type: Text/css');
    ?>
    /*
     CSS Code Here
    */
    ---------------------------
    Errors = Improved Programming.
    My Site

  4. #4
    SitePoint Guru Chroniclemaster1's Avatar
    Join Date
    Jun 2007
    Location
    San Diego, CA
    Posts
    784
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice. I would never have thought of putting a PHP header in a CSS file. Do you know if this is stable, or if it requires certain server settings?
    Whatever you can do or dream you can, begin it.
    Boldness has genius, power and magic in it. Begin it now.

    Chroniclemaster1, Founder of Earth Chronicle
    A Growing History of our Planet, by our Planet, for our Planet.

  5. #5
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know it's stable. I had forgotten about it but PHPMyAdmin uses the same technique.

    And you know how much PHPMyAdmin is being used.

    I don't think there are any server settings which require it as PHP's header() function is always there.
    ---------------------------
    Errors = Improved Programming.
    My Site


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
  •