I thought this would be easy, but how would i get the $base_url value in phptemplate?

Comments

thinkinkless’s picture

if you're trying to access the path (eg to display an image) you can use:

<?php print $directory ?>

working example:

<div style="margin: 10px 0 0 0;"><img src="/<?php print $directory ?>/images/someimage.gif" alt="" width="100" height="100" /></div>

note: this is for page.tpl.php

if you're looking for something else be a bit more specific.
hth!

Ken Collins’s picture

Thanks, I figured it out finally very late last night. I wanted to use this in serveral places in my page template, mostly instead of the print head command. Here is what I used.

<?php global $base_url; print $base_url;?>

And in context.

<base href="<?php global $base_url; print $base_url;?>" />
zach harkey’s picture

Alternatively you can use the GLOBALS array;

<?php print $GLOBALS['base_url'] ?>

Slightly cleaner and more compact.

-zach
--
harkey design

: z

whereisian’s picture

this thread cured a major headache

Rob T’s picture

Working OK for me on 6.6.

Tommy Sundstrom’s picture

Using <base> is no longer recommended.

pinxi’s picture

I just used $GLOBALS['base_url']. If this is not correct, what should I use?

$directory didn't work.

gunmajet’s picture

Did you try using $base_path?

pinxi’s picture

Sorry posted double

pinxi’s picture

I have Drupal in http://localhost/site.com/

$base_path only gives me http://localhost/

while

$GLOBALS['base_url'] gives me http://localhost/site.com/

The variable I am trying to set up is:

$path_link = $GLOBALS['base_url'].'/'$menu['items'][$mid]['path'];

spidrupal’s picture

You can use base_path()

Also path_to_theme() is useful at times.