Path to theme
Looking for the drupal path to your current theme? It can be helpful if you're making a theme and, for a change, you want to link directly to
print theme('stylesheet_import', base_path() . path_to_theme() ."/modules.css");
For our purposes, something like:
<img src="<?php echo base_path() . path_to_theme() . "/sample.png"; ?>" />
Now I'm not sure that "." in echo will work. Feel free to test it out for us!
UPDATE: To get print an image that is in your theme by getting its path, Agaric thinks the recommended approach is
<?php
print '<img src="'. path_to_theme() .'/images/picture.jpg" />';
?>
Or the Dan Hakimzadeh method of using imagecache, and therefore the files directory, from your theme:
<?php
$primaryimagexists = $node->node_data_field_user_picture_field_user_picture_fid;
if ($primaryimagexists != 0) {
print $field_user_picture_fid;
}
else {
print '<img src="/sites/example.com/files/imagecache/userpic_thumb/sites/example.com/files/images/LC-Sun.jpg">';
}
?>
Comments
Actually, the current official Agaric way
Should look something like this, to call for instance your custom logo, in an
images
folder in your theme directory, directly from your theme's page template file (page.tpl.php
):<img src="<?php print base_path() . path_to_theme() . "/images/sample.png"; ?>" alt="<?php print t('Home') ?>" id="logo" />
[Note: comment older than update above.]
Include the leading /
If you don't include the leading slash in your image paths, the URL will be wrong for non-home pages, if you don't include the base_path() in the URL.
So,
<img src="/<?php print path_to_theme(); ?>/images/your-image.png" />
P.S. your captcha is broken, rejecting on preview.
La la la-la
Faster to use commas than dots when calling 'echo' -- skip the string concat. ;)
MB
Post new comment