0

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!

Ta

  • 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 Feb 6 '15 at 15:12
  • @Robin I named the template field--field_photo--image.tpl.php but no joy. – user35763 Feb 6 '15 at 15:47
  • the machinename of your content type is called "image"? – Robin Feb 6 '15 at 17:22
0

Can you try:

$item['#attributes'] = array('class' => 'photo');
|improve this answer|||||

Your Answer

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