Drupal Theming – How to print the attached image?

If you are modifying Drupal theme and wish to play with attached image then following code might be helpful.

This code prints attached image (to a node) .

<?php
foreach ($node->files as $file)
{
$fileType = $file->filemime;
if($fileType == ‘image/jpeg’)
{
$imagePath = $file->filepath;
$imageTitle = $file->description;
print ‘<img class=”contentImage” width=”100″ height=”80″ src=”/’.$imagePath.'” alt=”‘.$imageTitle.'” title=”” />’;
}
}
?>

You can modify it as per your requirements. The above code prints all the attached images.

Leave a Reply