Page 1 of 1

Php Include in css

Posted: Sun Feb 19, 2012 6:22 pm
by dddmx3
This code generates a product image:

Code: Select all

<?php echo ps_product::image_tag( urldecode($product_thumb_image), 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?>
The code above generates a url to be used as a image for the given product. I want to set that generated url as the background of a css div. How would I be able to include php in css?

This obviously wouldn't work:

[text].style {
background: <?php echo ps_product::image_tag( urldecode($product_thumb_image), 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?>;
}[/text]

Re: Php Include in css

Posted: Sun Feb 19, 2012 9:20 pm
by Celauran
Hard to say for certain without seeing the code for ps_product::image_tag, but I'd try something like this:

Code: Select all

.style
{
    background-image: url('<?php echo urldecode($product_thumb_image); ?>');
}

Re: Php Include in css

Posted: Sun Feb 19, 2012 9:47 pm
by dddmx3
When I put it in the css, it showed up like this live:

.itemImage {
background: url("<?php echo urldecode($product_thumb_image);
}

It's like it's not even seeing the php. Then again it is a stylesheet...

Re: Php Include in css

Posted: Mon Feb 20, 2012 12:01 am
by azycraze
save the file as '.php' instead of '.css'.
and instead of linking css file,include the php file.Then you will be able to write the code as Celauran said.
Do
1) if your css file is 'css.css' make it a php file (say css.php)
2) include css.php where you have linked the css.css.

The css.php will look as
======================
<style>
.............
...............
...your codes..
............
#your_div_name {

background: url("<?php echo urldecode($product_thumb_image);

}
............
.............
</style>

======================================

Re: Php Include in css

Posted: Mon Feb 20, 2012 4:49 am
by Celauran
dddmx3 wrote:When I put it in the css, it showed up like this live:

.itemImage {
background: url("<?php echo urldecode($product_thumb_image);
}

It's like it's not even seeing the php. Then again it is a stylesheet...
Since you were trying to include some PHP, I assumed you were referring to CSS defined in the head of the document.