Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

e.g. this:

<a href="<?php echo $front_page; ?>" title="<?php echo t('Home');?>" rel="home" id="logo">
        <img src="http://localhost/jamesbondblog/sites/all/themes/jamestheme/images/logo.jpg">
</a>

is working.

But this is not:

<a href="<?php echo $front_page; ?>" title="<?php echo t('Home');?>" rel="home" id="logo">
        <img src="<?php echo $base_url; ?>/sites/all/themes/jamestheme/images/logo.jpg">
</a>

Can someone explain why?

I am using Drupal 7 and this code is in page.tpl.php

share|improve this question
    
What is your output for whats not working Q? –  Alex Gill Dec 5 '12 at 12:33
    
I have solved it meanwhile by myself: instead of <?php echo $base_url; ?> I need to use <?php global $base_url; echo $base_url; ?> –  Derfder Dec 5 '12 at 12:34
    
Can I ask why is this global variable not accessible by default? For security reasons? Thanks in advance. –  Derfder Dec 5 '12 at 12:35
    
Wasnt aware this was available to the page template which is probably why you couldnt get it ;-) –  Alex Gill Dec 5 '12 at 12:40
add comment

3 Answers 3

up vote 1 down vote accepted

what about global $base_path; ?

share|improve this answer
    
perfect ;). it's working and without any errors in admin! –  Derfder Dec 5 '12 at 13:08
add comment

Try this...

In your themes template...

function YOURTHEME_preprocess_page(&$variables) {
   global $base_url;
   $variables['base_url'] = $base_url;
}

In page template...

$base_url;
share|improve this answer
    
This way echo $base_url; outputs nothing. You have soething wrong with your code probably. But at least the message in admin of undefined variable dissappeared ;) –  Derfder Dec 5 '12 at 12:59
add comment

SOLVED (with an error message in admin :(

Instead of <?php echo $base_url; ?>

you need to use <?php global $base_url; echo $base_url; ?>

But it keeps saying in my modules this error message:

Notice: Undefined variable: base_url in include() (line 9 of C:\wamp\www\jamesbondblog\sites\all\themes\jamestheme\page.tpl.php).

Thanks in advance for a fix to get rid of this error message.

share|improve this answer
    
This isnt the way to go Q... –  Alex Gill Dec 5 '12 at 12:44
    
You can see what variables are available to page template. Go to /includes/theme.inc line: 2516 –  Alex Gill Dec 5 '12 at 12:45
    
I know it's wrong, but it is working in the template. Your way is outputing nothing. –  Derfder Dec 5 '12 at 13:00
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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