I'm displaying the latest 5 nodes (teaser view mode) in a sidebar region using views
. The nodes have an image field but I only need to render that on the first node on the list.
So, since the teaser view mode does include the image, I'm trying to remove the image from all nodes apart the first upon rendering.
I've tried the following in my theme's template.php
:
function foo_preprocess_views_view(&$vars) {
if (isset($vars['view']) &&
isset($vars['view']->style_plugin) &&
isset($vars['view']->style_plugin->row_plugin->nodes)) {
$first = true;
foreach($vars['view']->style_plugin->row_plugin->nodes as $node) {
if (!$first) {
unset($node->field_image);
}
$first = false;
}
}
}
But the image is still being rendered. I think that this has to do with the fact that I'm trying to temporarily remove the image from the wrong datastructure which represents the node state.
I then tried using the hook_preprocess_node
with something like:
unset($vars['field_image']);
But it still has no effect. The image was still there.
How is this solved? And at which layer is it solved best?
I know I could simply hide via CSS by using the .views-row-first
class but I don't think this is optimal.