Skip to content

Instantly share code, notes, and snippets.

@lincoln-chawora
Created September 11, 2019 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lincoln-chawora/76256be485e33757ea7fcb25ba53911f to your computer and use it in GitHub Desktop.
Save lincoln-chawora/76256be485e33757ea7fcb25ba53911f to your computer and use it in GitHub Desktop.
How to add classes to views rows programmatically in drupal 7
/**
* Implements hook_views_view_unformatted().
*/
function YOUR_THEME_preprocess_views_view_unformatted(&$vars) {
$results = $vars['view']->result;
$iteration = 0;
foreach ($results as $key => $result) {
if (empty($result->field_image)) {
$vars['classes_array'][$key] .= ' empty__' . ($iteration % 5 + 1);
$iteration++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment