Render a View in your template file

Render a View in your template file

If you are theming or something and work a lot with Views, you should know about: 

views_embed_view()

Using this function, you can embed Views and even dynamically pass them filter arguments. The first parameter is $name. $name is the name of the View and the second one is $display_id. $display_id is the machine name of the Display you want. If you only have one or you are fine with the default one, no need to specify the Display. Additionally though, you can add further parameters that get passed to the View as arguments. So for the use case above, you’d do something like this: 

print views_embed_view('related_posts', 'block', $node->nid); 

 

blog tag: