0
<img src="<?php print($base_path . drupal_get_path('theme', 'bartik')); ?>images/some-image.png">

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.

3

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(&$vars) {  
  $vars['base_path'] = base_path();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.