Hello,

My knowledge of Drupal is somewhat limited. I understand how to build a template conceptually but something that I'm having difficulty in practice is the placement of static images.

An example of what I am talking about is my attempt to convert a personal site of mine into a Drupal managed site. http://www.djpsiphon.com/

The issue that I am having is the images along the bottom below "Professional Audio Equipment Used by...". From what I have seen so far this is what is happening: If I create an images directory and place it inside the template folder of the new template that I am creating none of the images can be referenced because the images that I am trying to pull on are a local static resource buried in the templace folder but when the page is loaded the template directory is negated since the engine is making it onto the site.

ex: images are in folder: site.com/drupal/sites/all/themes/mytheme/images/
but page loads as: site.com/drupal/?q=node/1 ergo breaking the relative link to where the images are stored

I was wondering what the correct way to place and reference these static template content images are in the Drupal design conventions.

Comments

jeff h’s picture

Hi, a very valuable resource you may not have seen is the Drupal API reference at http://api.drupal.org/. If you go there and in the Drupal 5 search field, type "path" you'll see what functions are available regarding paths. You should turn up a function called path_to_theme() which will return the path to your current theme's directory.

Thus, I think something like the following should work for you:

<?php global $base_path; print $base_path.path_to_theme(); ?>/images/my-image.jpg

Jeff

PSIPHON’s picture

Thank you!

I wasn't sure if something like that existed, that solves the issue completely :D

- Eric

vitalsols’s picture

you are great :D

vitalsols’s picture

you are great :D

nunami’s picture

Thank you!

stephaniefuda’s picture

This was such a big help - Thanks!

I love Drupal. Always.

jpoesen@drupal.org’s picture

You should create a /files/images directory in the root directory of your drupal installation. Any graphical elements you reference in your template files should be kept there.

The /images directory in your template folder should only be used for graphical elements referenced by your style sheets (background images, list item bullets, etc).

That's the way I do it and it works fine for me.

jeff h’s picture

Your suggestion is definitely a valid option, but I would propose it's better to keep your images separated based on whether they are part of a theme design or part of a site's content. I decide this based on whether the image should still appear even if I changed the theme to a completely different one. Normally those types of images have been referenced inside a node or block.

Therefore, "content images" such as these I keep in a root-level files/images directory as you suggested, while images referenced by the theme (whether from CSS or inside tpl.php files) I put in an images directory inside my theme directory.

Jeff