0

I've developed a custom .tpl.php file for my View and in the past it has worked. Suddenly, while working on my Macbook using MAMP, Drupal decided that the $views->rows needs to be output as a String type and not an array. I've searched online and here for an answer but can't find one. I'm not doing any pre-process or views_render hooks in my template.php file for the theme. Does anyone have any ideas or have seen this before?

Thanks

jgrantd
  • 41
  • 4

2 Answers2

0

After going through the Views module code, I couldn't find a _render hook that I would alter to cause the $rows to go back to an Array type. I did go through the modules/views/theme/views-view.tpl.php

So I replaced most of the code in my own template with the views-view.tpl.php code, as well as replacing the database with a previous version so I could start completely over. Turns out the issue was with my template file not outputting the exposed filters and such, as well as Views using

print $rows

instead of using $rows as an array. Seems like whatever version of Views I'm using uses the $rows variable as a String. So I've put in a %SPLIT% string in the Rewrite Results box so that I can do a PHP preg_split, feed that resulting array into my function to generate what I need, then do a preg_replace to get rid of the %SPLIT% strings in $rows. The result looked like what I had.

So, bottom line, looks like Unformatted Fields in Views now outputs $rows as a String variable instead of an array.

jgrantd
  • 41
  • 4
0

I also discovered this when trying to theme a certain row differently if a condition was met. 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.