Skip to main content

Print a view in Drupal 7

Published on 5th February 2013

I never really appreciated how powerful views were until I started theming sites in Drupal 7.

  $viewName = 'VIEWNAME';
  print views_embed_view($viewName);

With the ability to render Views in a template (e.g. page.tpl.php), we can put any content anywhere. The options are endless!

You can place the above code into page.tpl.php, node.tpl.php or straight into the node content (you must have text format set to PHP code)

Just replace VIEWNAME with the machine_name of the View. To find the machine name, you can hover over the edit button or right click and copy link address e.g.