I use the following code to render the image from the template file. This code is used when the image name is known. Multiple images can be displayed by adding the same lines of code with different image names.

global $base_path;
print "<img src='" . $base_path . path_to_theme() . "/../../../default/files/styles/thumbnail/public/xyz.jpg' width='100' height='100' />";

Is it possible to render the multiple images from the content type with the field name created but without changing anything in the template file every time we upload the image?

  • What theme are you using? This functionality is pretty much built-in for most of them. – Mołot Aug 27 '13 at 9:53
  • I'm using my own theme i.e., custom theme – user20446 Aug 27 '13 at 10:09
  • Open one of ready-made themes and see how do they do it. It'll be easier that way ;) providing a large part of Theming Guide here is hardly possible. – Mołot Aug 27 '13 at 10:12
  • @Molot: As suggested I tried, but found no use!!!! – user20446 Aug 27 '13 at 10:22
  • 2
    @Mołot's comment could be on spot here. What is not clear to me is from where the image path is taken. If it is taken from a field, why don't you use an image field that shows uploaded image? With the right settings, it would show the uploaded image without any need to write any code. – kiamlaluno Aug 27 '13 at 13:30

If you have multiple images from the content type, and you want to render them. The .tpl.php file must have $node variable and in that variable you will have the image path and image uri for each image with field name, which you want to render. Just save the image path or image uri of image in some variable and do as following:

$img_uri = <image uri path here>;
$image_url = file_create_url($img_uri);
print '<img src="' . $image_url . '" width="100" height="100" alt="style image" />';

In case your are using Image Styles then you will need to get the image's url and style name and use it like this:

$style_name = <image style name>;
$file_path = <image file path>;
$image_url = image_style_url($style_name, $path);
print '<img src="' . $image_url . '" width="100" height="100" alt="style image" />';

And I can see that are using Image Style in which your path is something like:


The rest I think that once you get different image file paths then you can easily loop them as you like.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.