Closed (fixed)
Project:
Views (for Drupal 7)
Version:
7.x-3.7
Component:
node data
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
20 May 2014 at 18:54 UTC
Updated:
20 May 2014 at 18:54 UTC
I had a problem trying to theme a certain row differently because in the view I was working with, $rows was a string instead of an array. I wanted to theme a certain row differently if a condition was met. I know most things can be done in the Views UI but I couldn't figure out this one like that. I was finally able to do this with yourtheme_preprocess_views_view_unformatted(&$vars) in my template.php file. $rows seemed to still behave like an array there (although it went back to being a string later).
function yourtheme_preprocess_views_view_unformatted(&$vars) {
if ($vars['view']->name == "name_of_view") {
$rows = $vars['rows'];
$newRows = array();
foreach ($rows as $r) {
$test = strpos($r, "string_i_looked_for");
if ($test) {
$newRows[] = "<hr>$r"; // I needed to put in a divider if the condition was met.
}
else {
$newRows[] = $r;
}
}
$vars['rows'] = $newRows; // So that the array of new rows is what will be sent along.
}
}My actual problem required the divider only in the first instance of the test, so I also used a counter, but I think the example above gives the idea.