On our company website we have a people page which amongst others has an image field called 'field_photo'

This is being rendered using the following:

<?php print render($content['field_photo']); ?>

However I need to be able to add some attributes to the img tag outputted, to do this I figured I would have to use a custom template and add in the required bits like so:

$item['#item']['attributes']['class'] = 'photo'; 

Problem I am having is no matter what I do, I don't seem to be able to get this to work no matter what I name the template (eg field--field_photo--image.tpl.php). I'm not used to working with Drupal at all, so any help would be great!


  • first of all, "class" is an array, so use $item['#item']['attributes']['class'][] = 'photo'; Second, to overwrite a field template you have to use the naming convention field--field_name--content_type.tpl.php. Letme know if this does the trick
    – Robin
    Commented Feb 6, 2015 at 15:12
  • @Robin I named the template field--field_photo--image.tpl.php but no joy.
    – user35763
    Commented Feb 6, 2015 at 15:47
  • the machinename of your content type is called "image"?
    – Robin
    Commented Feb 6, 2015 at 17:22

1 Answer 1


Can you try:

$item['#attributes'] = array('class' => 'photo');

Your Answer

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