Same image for all custom block

Permalink 1 user found helpful
Hi!
I want to make a custom block (classic product information).
All instances of that block must have the same image (a shopping cart).
There's a way to embed it in the code, without selecting it for every block's instance I create?

I've tried to put that image in the block's folder and in the theme's folder, giving both the full and the relative path, but I can't see the image on the page... Where I have to put it??

Thanks in advance,
Teo

 
jordanlev replied on at Permalink Best Answer Reply
jordanlev
Is the image being outputted as an html <img> tag, or from your CSS (as a background image)?

If it's an <img> tag, then you can just put it in your block directory and do some code like this in your block's view.php file:
<img src="<?php echo $this->getBlockURL(); ?>/your-image.png" alt="shopping cart">


If, on the other hand, you are referencing the image in CSS, then you don't need to use any kind of function to get a path... CSS urls are always relative to the CSS file itself (not the page's URL), so you can just put the image in the same directory as wherever the CSS file is and do this:
background-image: url(your-image.png);


Hope that helps!

-Jordan
T30 replied on at Permalink Reply
It was exactly what i was looking for!
Nice to meet getBlockURL() function, thanks!