6

I'm trying to render the rows in a view manually using the Views API. The style plugin is the "Unformatted" plugin. This is my code:

<?php
$view = views_get_view('nearme');
$view->execute('default');
$view->preview();

$renderer = $view->style_plugin->row_plugin;
foreach ($view->result as $row) {
  echo $renderer->render($row);
}
?>

This code almost works - it renders essentially a blank row. My "Global: custom text" field is rendered, as are some generic labels and field HTML, but the actual values from $view->result are not interpolated.

What am I doing wrong?

14

The tokens in views requires $view->row_index to be set to be able to get the right rendered fields.

$view = views_get_view('nearme');
$view->execute('default');
$view->preview();

$renderer = $view->style_plugin->row_plugin;
foreach ($view->result as $index => $row) {
  $view->row_index = $index;
  echo $renderer->render($row);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.