I upload multiple images to a node using one content type image field. I need to render the file name for each image under the image when viewing the node, all I get at the moment is just a page of images. Tried a view but that REALLY screws everything up. Any ideas how this can be done on the node?


2 Answers 2


You can do this using hook_preprocess_node() either in your theme's template.php file, or a custom module file. You'll want to use API functions to get the data from the node rather than accessing the arrays directly, so you don't need to worry about language codes etc.

function MYTHEME_preprocess_node(&$vars) {
  $node = $vars['node'];

  if ($node->type == 'the_type' && $vars['view_mode'] == 'full') {
    $field_items = field_get_items('node', $node, 'field_name');

    if (!empty($field_items)) {
      $filenames = array();
      foreach ($field_items as $item) {
        $filenames[] = $item['filename'];

      $vars['filenames'] = theme('item_list', array('items' => $filenames));

You can obviously change the output to whatever HTML you need, but the above will produce an unordered list of image filenames, available in the $filenames variable in your node.tpl.php file.


in templete.php file create

    function THEMENAME_preprocess_node(&$vars){
       dpm($vars)//find image name etc with devel module enabled
       //for example i have field - field_image first element is 0 and filename is = file_name
       $vars['image_name'] = $vars['field_image'][0]['file_name']; //i have created a new variable
  //  $image_name, now u can out this variable in your tpl file

output them in your *.tpl.php file do this

<?php print render($image_name) ?>

you can actually put them into array and foreach

  • That looks suspiciously like Drupal 6 code...
    – Clive
    Sep 6, 2012 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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