conditional removal of a field in a view 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(&amp;$vars) {
  if (isset($vars['view']) &amp;&amp;
      isset($vars['view']-&gt;style_plugin) &amp;&amp;
      isset($vars['view']-&gt;style_plugin-&gt;row_plugin-&gt;nodes)) {
    $first = true;
    foreach($vars['view']-&gt;style_plugin-&gt;row_plugin-&gt;nodes as $node) {
      if (!$first) {
        unset($node-&gt;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.
Take a look at Views Nodes Split. Module Monday: Views Nodes Split gives more information about how to use the module.


  Setting up the module is simple: just turn it on, and build your View as you normally would. Then, click on the View's Format option and select the newly available "Splited Content" row style. While the grammar is awkward, the results are great: you can specify separate build modes and display styles for the first node and all subsequent nodes from a simple config screen. In fact, you can even adjust where the cutoff happens: you might want the first three nodes to display in full, for example. No other changes are needed for your View; this module's new row style handles the rest.