Explicity rendering of views

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
gomezbl's picture

Hi, I'm trying to explicity rendering at code level a view defined in my solution.

This is, suppose the name of the view is my_last_comments, and I'd like to show that view in a very specific place in my page template, say, so I'd like to get the view rendered in a preprocess variable such as:

function theme_preprocess( &$vars ) {
$vars['mylastcommentsview'] = view_render( 'my_last_comments' );
}

Got the idea?. I've looked for that in views module function but I couldn't find anything.

I'd appreciate some help in this.

Thanks

Comments

Hi, the function name is

ziobudda's picture

Hi, the function name is "views_embed_view" that accept three parameters:
1) the name of the view
2) the display to use
3) an array for the argouments' view (this is optional)

In your case:

$vars['mylastcommentsview'] = views_embed_view("my_last_comments","block_1");

If you want to display a view where the argoument to use is the user uid that see the page:

global $user;
$vars['mylastcommentsview'] = views_embed_view("my_last_comments","block_1",array($user->uid));

M.

thanks

gomezbl's picture

I skipped that function, surely. That's exactly what I was looking for.

Thanks

RafaBlanes
contacto@ellibronegrodelprogramador.com
Agile Drupal Development and more...