Explicity rendering of views

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.



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));



gomezbl's picture

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


Agile Drupal Development and more...

Drupal Dojo

Group organizers

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week