Wednesday 7 December 2011

Drupal: How To Programmatically Add, Embed Or Insert Views In Your Theme tpl

The Views module is one of the best things to have happened to Drupal. Views provides an easy way for any Drupal site designers to present how lists and tables of content. Views has a smart query builder that can build the proper query, execute it, and display the results. In this article we will tell you how to programmatically add, embed or insert Views in your theme's tpl. 
You can easily embed your pre-configured views in your theme's TPL using this command:

The Views module is one of the best things to have happened to Drupal. Views provides an easy way for any Drupal site designers to present how lists and tables of content. Views has a smart query builder that can build the proper query, execute it, and display the results. In this article we will tell you how to programmatically add, embed or insert Views in your theme's tpl. 
You can easily embed your pre-configured views in your theme's TPL using this command:

The snippet above shows a variable $display_id which is set to block_2. The illustration below shows how to find out the value for $display_id corresponding to the Display of the view that you want to embed in your website, progammatically.


The function views_embed_view won't display the title of the view. In order to get the title of the view, you can use the following code snippet:
$view = views_get_view($view_name);
print $view->get_title();

No comments: