How To Call view in template in Drupal ?


The Views module is the most downloaded contribution on It is a very powerful list-maker that not only provides a GUI for creating a query but also gives you options on how you want to display your data. This is an introductory tutorial to the world of Views and how you can use this great module to create listings of content.

<?php print views_embed_view('blog_posts', 'block'); ?>

The first option is the machine name of the view, this is found if you hover over the edit link on the views page and look at the link address. The second is the block or page machine name, so if its the first block it would be block or block_1.

When calling the embed view function you have to follow the same order in which the contextual filters are added. ie, If you have added two contextual filters Nid and Uid in the give order.

Then while calling the views embed view you have to follow the same order

<?php $content = views_embed_view('<view_name>', '<display_name>', $nid, $uid); ?>

Drupal allows you to use views as pages and as blocks. You can apply templates to that pages and blocks, and you can put blocks in regions. By calling views from template

Add new comment