I have the following snippet.
function <themename>_preprocess_node(&$vars) {
if ($vars['teaser'] && !$vars['is_front']) {
$vars['theme_hook_suggestions'][] = 'node__teaser';
}
elseif ($vars['teaser'] && $vars['is_front']) {
$vars['theme_hook_suggestions'][] = 'node__teaser__front';
}
if (!$vars['teaser'] && count($vars['field_related']) > 2) {
$vars['theme_hook_suggestions'][] = 'node__alt';
foreach (element_children($vars['content']['field_related']) as $k) {
$vars['content']['field_related'][$k]['#attributes']['class'][] = 'grid_1';
}
}
}
Basically, I have this field_related in my node that holds from 0 to 3 values. If it holds more than 2 values, I change the template suggestion (node__alt) and I'd like to attach a class (grid_1) to each of the values. I've spent the last 4 hours researching but nothing got me even near to where I want to go.
Do you have any idea?
EDIT In the template file I did like this:
<aside id="related">
<?php foreach(element_children($content['field_related']) as $k) : ?>
<div class="grid_1">
<?php echo render($content['field_related'][$k]) ?>
</div>
<?php endforeach ?>
</aside>
It works, but it is far from being clean.