By haopei on
Hello everyone,
I'm a drupal theming newcomer.
I'm working with this custom theme right now, and I've created the .info file.
I have set the stylesheet like this
stylesheets[screen][] = sites/all/themes/mytheme/style.css
The theme receives the custom .css fine, but the images are not showing.
My images folder is located in: sites/all/themes/mytheme/images
my page.tpl.php file is inside the mytheme folder, and its html calls to images in the /images folder. For example:
<img src="images/graphic.png" />
What am i doing wrong?
Comments
You don't need to specify the
You don't need to specify the full path to your style.css file. Write the path relative to where your .info file is, which should be at mytheme/mytheme.info ... so your CSS line should read:
stylesheets[screen][] = style.cssTry this and let me know if you're still experiencing issues.
Hi Keyz, Thanks for such a
Hi Keyz,
Thanks for such a quick reply.
I have done what you recommended and specified the path of the .css file relative to the location of the .info file. However, the images are still not working!
What path are you specifying
What path are you specifying for your images within the CSS file? It should be a path relative to your theme root, like
.something { background-image: url(images/file.jpg); }If you call up an image from page.tpl.php however, it needs to have a path absolute to your site root, like
<img src="/sites/all/themes/mytheme/images/file.jpg" />. You can generate the path if preferred using code like<?php print '<img src="'. $base_path . path_to_theme() . '/images/file.jpg' .'" />'?>Page.tpl.php is a template
Page.tpl.php is a template for generating pages. Your image locations need to be referenced relative to the location of your site's generated pages. In your case you should call images like this:
<img src="/sites/all/themes/mytheme/images/graphic.png />Using /images will only work if you're calling images with CSS in your stylesheet.
example: background: url(images/graphic.png);
Thanks ericprk, that
Thanks ericprk, that worked!
But does this mean I need to use that (deep) path for all the images used on my website? it seems rather inefficient.
Like Keyz said your image
Like Keyz said your image folder is relative to the root of your site. If you want a shorter path, move your image folder somewhere else. It doesn't have to be located in your theme folder.
Thank you both. It's working
Thank you both. It's working fine :)
I used the
<?php print '<img src="'. $base_path . path_to_theme() . '/images/image.png /></a>' ?>method.I assume this is the best practice?