Hard-coding images into block templates

Permalink 1 user found helpful
I need to include an image in a custom block template. To locate the image (which I've placed in an 'images' folder with the template) I'm using this PHP:

echo str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->getBlockPath()) . '/templates/templatename/images/image.png'

Am I missing a neater way to do this or is this the best solution?

Joe

jawbonelid
 
jordanlev replied on at Permalink Reply
jordanlev
Try:
echo $this->getBlockURL() . '/templates/templatename/images/image.png';


I've also tried dynamically outputting the current template name so that doesn't need to be hardcoded in the path, but could never get it to work so as far as I know the above code is the simplest/best way to go.
jawbonelid replied on at Permalink Reply
jawbonelid
Ah! I had a hunch there might be some other way. Hard-coding the rest of the path not a problem as it is a custom template, doesn't need to be that portable.
Thanks!

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.