I have an HTML file and some images. While theming, I have used the function drupal_get_path
to display the images, but none of them are showing. I have already tried the code below. If anyone could help, it would be a great help.
<?php echo drupal_get_path('theme', 'THEME_NAME'); ?>/images/slider/slide1_baner1.jpg" alt="" />
Use $GLOBALS['theme'] for get the current theme's path (Optional).
Use theme_image to get the html of an image.
The Drupal way for resolving this problem would be something like this:
$variables = array(
'path' => drupal_get_path('theme', 'THEME_NAME').'/images/slider/slide1_baner1.jpg',
'alt' => 'Alt of image',
'title' => 'Image title',
'width' => '50%',
'height' => '50%',
'attributes' => array('class' => 'img-class', 'id' => 'banner1'),
);
$output = theme('image', $variables );
Please try using the below way!
<?php global $theme; // Returns the current active theme name. ?> <img"<?php echo drupal_get_path('theme', $theme); ?>/images/slider/slide1_baner1.jpg" alt="" />
Just try once to debug that what the drupal_get_path()
returns. May be for you, it's not returning the exact browse-able path and that's why the images are not coming.
Keep Drupalizing :)
I recently asked a similar question on Drupal Answers: https://drupal.stackexchange.com/questions/121488/whats-the-correct-relative-path-to-a-local-image .
You can use the code
<?php global $base_url; ?>
<img src="<?php echo $base_url; ?>/sites/all/themes/MY-THEME/images/slider/slide1_baner1.jpg">
or the function file_create_url
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.