Give unique class to last item in view UPDATE: I now see that drupal has a built in setting you can check to add even/odd,first, and last classes to the items in the view. Is there a way I can append another class to the last item using this?



For responsive purposes I was planning on adding the bootstrap .hidden-lg class to the last item in a view. This is in order to display more items when I go from a 3 column to a 2 column view. I did see that there was a style output template for views that iterates through each of the rows (as you can see below) but I wasn't sure how to take advantage of that. 

&lt;?php

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
 */
?&gt;
&lt;?php if (!empty($title)): ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
  &lt;div&lt;?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?&gt;&gt;
    &lt;?php print $row; ?&gt;
  &lt;/div&gt;
&lt;?php endforeach; ?&gt;


Unless the only option is to perform some regex on the last item of the foreach statement.

As a heads up, I'm already outputting the content and applying custom classes using a view field output template.
You may try next code snippet
    

/**
 * @file
 * Default simple view template to display a list of rows.
 *
 * @ingroup views_templates
*/
end($rows);
$last = key($rows);
?&gt;
&lt;?php if (!empty($title)): ?&gt;
  &lt;h3&gt;&lt;?php print $title; ?&gt;&lt;/h3&gt;
&lt;?php endif; ?&gt;
&lt;?php foreach ($rows as $id =&gt; $row): ?&gt;
&lt;?php if ($id == $last): ?&gt;
    &lt;?php $classes_array[$id] .= ' last-element'; ?&gt;
&lt;?php endif; ?&gt;
  &lt;div&lt;?php if ($classes_array[$id]) { print ' class="' . $classes_array[$id] .'"';  } ?&gt;&gt;
    &lt;?php print $row; ?&gt;
  &lt;/div&gt;
&lt;?php endforeach; ?&gt;