2

I am getting this error, but everything else is fine; even that variable is getting printed. Then why does the error appear?

Notice: Undefined variable: base_url in include() (line 26 of htdocs\atins\drupal\sites\all\themes\live\html.tpl.php).

Notice: Undefined variable: base_path in include() (line 26 of htdocs\atins\drupal\sites\all\themes\live\html.tpl.php).

This is my code:

<a href="<?php print $base_url;?>"><img src="<?php print $base_path . $directory; ?>/img/logo.png" height="35" width="211" alt="AtinsLive Logo" title="Home" /></a>
6

You will need to bring the variable $base_url and $base_path into the global scope. At the top of your function or template file add:

global $base_path, $base_url;

or call base_path()

  • 3
    Actually, l() should be used in this case. – kiamlaluno Sep 26 '11 at 15:31
  • 2
    I agree with Kiamlaluno. l() should be used in the case above. Shoaib Nawaz is also correct, the base_path() function is better used. But in the case of being able to use the 2 variables, you can bring them into the global scope. This is not ideal. – harry Sep 26 '11 at 16:24
1

I ran into this same issue when using $base_url in page.tpl.php in the following:

print l(theme('image', array('path'=>path_to_theme().'/css/images/logo_orig.png')), $base_url, array('html' => 'true'));

I fixed this by preprocessing $base_url in template.php:

function yourTheme_preprocess_page(&$vars, $hook) {
  global $base_url;
  $vars['base_url'] = $base_url;
}

So, I'm thinking you can preprocess you html template as well. This will be cleaner that calling a global in your tpl directly.

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.