For some reason pathing to my theme folder to access an image using <img src="<?php print base_path() . path_to_theme() . "/images/arrow-sm.gif"; ?>" alt="Arrow" width="12" height="15" border="0"/> is not working?

Is there some kind of specific code I am missing?

<div class="box">
<div class="right-box-third-top">&nbsp;</div>
    <div class="right-box-third-middle">
<div class="featured-img"><?php print $node->field_featured_img[0]['view'] ?></div>

<div class="more-info"><a href="<?php print $node->path ?>" title="<?php print $title ?>">More Info <img src="<?php print base_path() . path_to_theme() . "/images/arrow-sm.gif"; ?>" alt="Arrow" width="12" height="15" border="0"/></a></div><h1><a href="<?php print $node->path ?>" title="<?php print $title ?>"><?php print $title ?></a></h1>

<?php print $node->content['body']['#value'] ?></div>
    <div class="right-box-third-bottom">&nbsp;</div>
</div>

Comments

Sorry, i should mention that

Sorry, i should mention that code above is in the contemplate module.

I have experienced the same

I have experienced the same problem. The way (terribly inelegant and *NOT* the right way) that I overcame it was by hard-coding the URL to the image. I could not find a better way to do it. No combination of the two functions you mentioned would work for me either.

Hmm this is quite annoying!

Hmm this is quite annoying!

I have found the Drupal

I have found the Drupal community can either be VERY helpful or... well... I think this thread exemplifies the Drupal forum support experience perfectly.

Simple question, not clearly explained in any documentation, and not a single person who understands what's going on can be bothered to help.

My image links are still hard-coded... sigh...

mine to.. oh well.

mine to.. oh well.

This is not a trivial

This is not a trivial question ok, and bashing the help won't make them work harder either. I would stongly suggest that you ask in the contemplate issue queue - this is a very specific issue/question and quite possibly only regular users or the developer might now the answer.

Have you read this - http://drupal.org/node/194098 , in particular comments #38 & 39

What about the API docs - have you read those, afaikt calling path_to_theme() is highly likely to be problematic in this case and is probably either empty or returning the wrong path.

The OP does not provide any output of this code, so we cant even see what its generating - this assumes we have either flat out know the answer (not likely since this is an edge case) or are prepared to take the time to replicate this AND debug it.

Please keep on-topic, your post is rather pointless and does not actually offer any help.

Ok, the problem is

Ok, the problem is non-trivial. To a drupal newbie (like myself), more things than not are non-trivial (like trying to understand the API docs).

Both of us are trying to link to images that are stored in custom themes.

What is the correct way to link to images in a custom theme, without hardcoding the image url?

...

EDIT - I had to remove my

EDIT - I had to remove my non-constructive comment.

try putting your contemplate code in a tpl file

create a file called node-your_content_type.tpl.php in your theme directory put your contemplate code there.

Travis Christopher

Try viewing the source code

Try viewing the source code of your website. See if base_path or path_to_theme prints any output.

Secondly, where did you place this template file?

-----
Drupal theming services, PSD to Drupal
http://kahthong.com

KahThong.com - My portfolio. PHP Web Developer from Malaysia.

...

Astounding - you claim to offer Drupal theming services yet fail to know the difference between contemplate module ("templates" are saved in the database) and standard drupal theme templates?

Need help with IE?
Learn basic XHTML and CSS first.
Get Firebug.

You're not completely right.

You're not completely right. Do not simply shoot people before knowing things correctly.

Contemplate allows you to place physical file in your themes directory or in sites/all/contemplates.
Read up their documentation.

Basically, when you already have these *.tpl.php files saved, you can optionally remove Contemplate too (this module only serves as a helper for you to get the variables of your nodes printed).

If you do not want to use Contemplate, simply create node-*.tpl.php and place the following code inside:
<?php print_r($node); ?>

Get it now? We here are trying to help you guys out. Yet you're acting as if we're wasting our time.
So, I was just trying to make things clear before concluding something.

If you do not wish to help, then don't.

.. bashing the help won't make them work harder either ..
Please keep on-topic, your post is rather pointless and does not actually offer any help.

Taken from your comment above.

-----
Drupal theming services, PSD to Drupal
http://kahthong.com

KahThong.com - My portfolio. PHP Web Developer from Malaysia.

I m solving file path in contemplate this way

I m not sure it's a good way. But it works for me.
I have a small function in my template.php file -

<?php
function file_path($filename, $imageCache = '')
{
   
$presetDir = (empty($imageCache))? '' : "imagecache/$imageCache/";
    return
base_path() . path_to_theme() . '/../../files/' . $presetDir . $filename;
}
?>

Now I can call it from contemplate or anywhere

// Just the file
<img src="<?php print file_path('image.jpg') ?>">
<img src="<?php print file_path('a-dir-in-files/image.jpg') ?>">

// Imagecache preset of file
<img src="<?php print file_path('image.jpg', 'medium_thumb') ?>">

If you use a theme from sites/all directory, may be you have to make little tweak.
Thanks.

---
Anis uddin Ahmad
Lead Developer | Right Brain Solution Ltd.
http://ajaxray.com

@Anis uddin Ahmad, FYI: this

@Anis uddin Ahmad, FYI: this solution does not work when rendering a contemplate-teaser template via a view set to render nodes. The path_to_theme is still coming up wrong with: sites/all/modules/views/ instead of the actual theme-path.

Merging Technology with Creativity
Fountain City Productions
http://fountain-city.com

Try using this:

$path = drupal_get_path('theme','nameofyourtheme');

where: nameofyourtheme is the name of your theme.

Merging Technology with Creativity
Fountain City Productions
http://fountain-city.com

nobody click here