Adding attributes to field_view_value I'm using the following function to render a image field in a template, this works great but I would also like to add a custom alt attribute to the image:

function &lt;module&gt;_render_field($node, $field_name, $delta = 0, $display = array()) { 
   $field = field_get_items('node', $node, $field_name);
   $field = field_view_value('node', $node, $field_name, $field[$delta], $display);
   return render($field);  
}

&lt;module&gt;_render_field($node, 'field_image', 0, array(
  'type' =&gt; 'image',
  'settings' =&gt; array(    
     'image_style' =&gt; 'object_380x250',
     'image_link' =&gt; 'content',
   ),
));


I was trying to add the alt attribute to the image by changing the above code to:

&lt;module&gt;_render_field($node, 'field_image', 0, array(
  'type' =&gt; 'image',
  'settings' =&gt; array(    
     'image_style' =&gt; 'object_380x250',
     'image_link' =&gt; 'content',
   ),
      'attributes' =&gt; array(
         'alt' =&gt; 'alternate'
      )
));


The above didn't worked but I managed to add the attribute by changing the module code to:

function &lt;module&gt;_render_field($node, $field_name, $delta = 0, $display = array()) { 
   $field = field_get_items('node', $node, $field_name);
   $field = field_view_value('node', $node, $field_name, $field[$delta], $display);
   // add alt attribute
   $field['#item']['alt'] = 'alternate';
   return render($field);  
}


I'm hoping there is a nicer way to achive this.
If you look at it, you'll notice MODULE_render_field is not useful at all. Once you get the renderable array from field_view_value you can change the values in it and render it. If you're adding that to a template, it will look fugly, for sure. But it belongs in a preprocess call, where it will look just normal:

&lt;?php

function MYTHEME_preprocess_SOME_TEMPLATE($vars) {
  $field_items = field_get_items('node', $vars['node'], $vars['field']['field_name']);
  $field_value = field_view_value('node', $vars['node'], $vars['field']['field_name'], $vars['field'][$delta], $display);
  // Alter the renderable array.
  $field_value['#item']['alt'] = 'alternate';
  $vars['altered_field'] = $field_value;
}


And in the template:

&lt;div class="something"&gt;
 &lt;?php print render($altered_field); ?&gt;
&lt;/div&gt;