3

I have about three views that will be used; Here's Daniel Wehner's answer:

 $view = views_get_view(); 
 $view->set_display();
 $view->filter['foo']->value = 'bar'; 
 print $view->preview($display_id, $args);

I built this based off his code, which while works, could be improved if including views is going to be a regular activity throughout your project:

$view = views_get_view('nodequeue_3');
$view->set_display();

$content['raw_markup'] = array(
  '#type' => 'markup',
  '#markup' => $view->preview(),
);

I'm also thinking this might not be done that often, because if you can build a module, why use views?

The utility of views should not be overlooked, in combination with (or without) a custom module.

Thanks for the patience, this community is awesome!

  • 2
    Try views_embed_view()? – GrayB Mar 8 '12 at 3:11
1

I prever to use this small helper function:

function mymodule_embed_view($view_id, $display_id, $arguments) {
    $view = views_get_view($view_id);
    $view->set_display($display_id);
    $view->set_arguments($arguments);
    $view->pre_execute();
    $view->execute();
    return $view->render();
}

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.