Display Suite - Getting even more control of your fields
When you want even more control over an outputted field, you can still put a theme function in template.php file. With the devel module enabled, set the display mode for a field to expert then add the following to template.php, clear your cache and then load a page with the field on it.
/**
* Implements hook_field__expert__FIELD_ID().
*/
function mytheme_field__expert__myfield(&$variables) {
// Inspect the contents of $variables.
krumo($variables);
// Pass back to the display suite theme function for final theming.
return theme_ds_field_expert($variables);
}
In this manner you can inspect the variables in $variables, make changes to them then let display suite format the output as before.
A good item to inspect is $variables['element']['#view_mode'] which will give you the current view mode the field is being rendered in. If you have a view list of teasers for instance, this will say teaser, allowing you to then modify the field just on that one display, leaving the output on the main node page alone. Below we see an example of just outputting one image of an unlimited image field in teaser mode.
/**
* Implements hook_field__expert__FIELD_ID().
*/
function mytheme_field__expert__field_images(&$variables) {
if ($variables['element']['#view_mode'] == 'teaser') {
// In teaser mode, only output the first image.
$item = $variables['items'][0];
$variables['items'] = array(0 => $item);
}
return theme_ds_field_expert($variables);
}