Drupal - Correct image path to use in template files of custom themes
I think these functions could be useful in your templates:
print base_path() . path_to_theme();
path_to_theme() Return the path to the current themed element. base_path() The base path of the Drupal installation.
for example, I have an image called bg-bar.png
inside images
directory in my template directory called garland
. then I can use base_path()
and path_to_theme()
to get the path to the image, for example inside node.tpl.php:
print '<img src="'.base_path() . path_to_theme() .'/images/bg-bar.png">';
Update: if you want to use the current domain, you can use global $base_root
:
$address = ''.base_path() . path_to_theme() .'/images/bg-bar.png';
global $base_root;
echo '<img src="' . $base_root . $address . '">';
I hope information be useful.