I can use a template preprocess function for node to simply get the alt tag of an image field image using the venerable field_get_items
as such:
function MYTHEME_preprocess_node(&$vars, $hook) {
// Global node.
$node = $vars['node'];
$field_image_items = field_get_items('node', $node, 'field_image');
// Load individual data from 'field_image'.
$vars['alt_caption'] = $field_image_items[0]['alt'];
}
Then in node.tpl.php
, I can render the alt tag of the image from the variable we created above as:
<?php print $alt_caption; ?>
... and that works great.
However, I'd like to customize the template for the image itself so when I create a field--field_image.tpl.php
template, sure enough the image renders fine but if I add the $alt_caption
variable, that does not render. I'm guessing this will simply not work or there is an extra step I need to do for the variable to render in this new template.