I just discovered that I can not use relative image paths in page.tpl.php as in ...

<div><img src="images/panelleftcorner.gif" /></div>

What is the proper way to reference images located in the themes directory? Is there a PHP variable that give me this path?

Comments

vm’s picture

for something like that, wouldn't you reference the image in the .css file ?

artcoder’s picture

Yes, I could. But what if it was an clickable image such as ...

<a href="http://www.drupal.org"><img src="images/drupal-mug-shot"></a>

Or what if I wanted the image to be a spacer image to prop up some div or table cells.

<div><img src="images/spacer.gif"></div>

In both cases, I would need the image to be a Only local images are allowed. tag rather than an css background image.

artcoder

mdixoncm’s picture

Except that using spacer images is not really the done thing in these enlightened times :)

Anyway - to reference your paths you should ideally use the url function - so you end up with something like

<div><img src="<?php print url('images/spacer.gid');?> /></div>

Hope that helps ...

mike

Like books? Check out booktribes the new (Drupal based) community for book lovers
from Computerminds

dman’s picture

if you want to develop a theme, read the theme developers guide, the phptemplate guide

When coding in paths to images used by your theme, you'll want
<img src="<?php print url($directory) ?>/images/thing.gif" />

this will produe the correct path to wherever you are building your theme ... and be portable as well. You do NOT want to reference images with hard-coded paths.

For that matter, you do not want to use 'spacer.gif' unless your target audience is browsers older than 4 years. It sorta gives your code a turn-of-the-century look.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

artcoder’s picture

Yep. Works great. The url function was what I needed.

artcoder