How to print correct path to file in .tpl.php? &lt;img src="&lt;?php print($base_path . drupal_get_path('theme', 'bartik')); ?&gt;images/some-image.png"&gt;


The above code works only if you're in the homepage. If you go to any inner page, it looks for image inside the current URL, not just base URL.

So, it prints the image if you're under www.address.com but if you're under www.address.com/page, it doesn't print the image, because now it's looking for it inside e.g. www.address.com/page/sites/all/themes/bartik/images/some-image.png the problem is, it includes the /page/ part.

In source, the image URL doesn't include the full path (which is the problem I believe?), only the sites/all/themes/bartik/images/some-image.png part.
It appears $base_path is empty, which would suggest your code isn't in page.tpl.php (where that var is commonly available, having been added in template_preprocess_page()).

To make it available to your current template, implement a preprocess hook like the following, which is for a region.tpl.php template file:

function MYTHEME_preprocess_region(&amp;$vars) {  
  $vars['base_path'] = base_path();
}