I read tons of solutions how to render an image in a PHPtemplate where I have the whole node in $content, however I don't get how to render it using a $node object, including the given image style etc.

So I got all the code working and can access the node title for example via:


How do I generate the proper HTML for this node (in this example the machine tag is field_slideshow_image)?

This line does not work, it gives me a 404 for the image URL:

<img src="<?php print image_style_url('slideshow', $node->field_slideshow_image['und'][0]['uri']); ?>" /> 

however, it contains at least the name of the actual image…


I found out that I have to force an image creation if there was none before, so now it works using:

$image_uri      = $node->field_slideshow_image['und'][0]['uri']; // or any public://my_image
$style = 'slideshow';
$derivative_uri = image_style_path($style, $image_uri);
$success        = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);

$new_image_url  = file_create_url($derivative_uri);
echo $new_image_url."<br /><br />";
echo "<img class=\"slideshow_image\" src=\"".$new_image_url."\" />";

However, the image style "slideshow" does not get applied! I tried it with the default "thumbnail" and that one works well.

  • Well, what is in $node->field_slideshow_image, eg, if you throw in a drupal_set_message('<pre>' . print_r($node->field_slideshow_image, TRUE) . '</pre>'); what information do you have to work with? Then just make sure you are sending a path to api.drupal.org/api/drupal/modules!image!image.module/function/…
    – Jimajamma
    Apr 14 '14 at 23:53
  • Thanks for your answer, I solved the 404 problem and updated my post.
    – tamasgal
    Apr 15 '14 at 0:02
  • 1
    Why don't you use just <?php print render($content['field_slideshow_image']); ?>? Apr 15 '14 at 4:04
  • 1
    In first line 404 is hard to explain. Anyway, you should not need to manually echo img tag. See this question if you need finer control than the command @ЕлинЙ. provided allows.
    – Mołot
    Apr 15 '14 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.