I'm learning views in drupal 7 and I just created an unformatted list view that is displaying the titles of a few nodes. The preview looks great and so does the view page.

I have a div block in a custom node template that I want now to view this "view" in. What code do I need to put into my node template to access the view function?

I looked at the system view template (views-view.tpl.php) that is generating what I want and I see that there is a $rows variable:

<?php if ($rows): ?>
  <div class="view-content">
    <?php print $rows; ?>

But when I place that into my node template it doesnt work (probably because I need a preproccess?).

Am I going about this the wrong way? Is there an easier way to get views into another template file? I considered using a block. But I thought that once I nail this, then I don't have to mess with blocks.

FYI: I saw this post but I am not sure where to put the code that he recommended.

Thanks! I really appreciate it.

1 Answer 1


Drupal 6

  $view = views_get_view('view-name');
  print views_build_view('embed', $view);

Drupal 7

<?php echo views_embed_view('view-name', $display_id = 'display-name') ?>
  • Thank you! Worked great. For those who are as new as me...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
    – Dan
    Dec 12, 2012 at 20:33
  • Great, glad it worked, can you edit your tags d6 or d7
    – devunder
    Dec 12, 2012 at 20:42
  • 1
    Ah sorry, I put it in the body of the message. Consider it done.
    – Dan
    Dec 12, 2012 at 20:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.