Created
September 11, 2019 14:01
-
-
Save lincoln-chawora/76256be485e33757ea7fcb25ba53911f to your computer and use it in GitHub Desktop.
How to add classes to views rows programmatically in drupal 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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