I wish to run PHP within a css file. The reason for this is that I want to dynamically set the URL of a background image based upon whether the site is in development or production. i.e
<?php Header ("Content-type: text/css; charset=utf-8");
$baseUrl = $this->basePath();
if (defined('RUNNING_FROM_ROOT'))
{
$baseUrl .= '/public';
}
?>
.readersSlidersOne {
background: url("<?php echo $baseUrl ?>/Images/backGroundImages/side_wallet.png") scroll 0 0 transparent ;
}
the above if clause basically determines whether a full BASE URL SHOULD be used or just the /public
i am aware from this answer that the solution is to create a css file with a php ending- and to then place the code below at the top of the file:
Header ("Content-type: text/css; charset=utf-8");
i did try this and it does indeed create a CSS file with PHP tags (css.php).
However once I place actually php code within the file it stops working.
i.e
$baseUrl = $this->basePath();