Drupal – Render a View in PHP Code

We can render a block in PHP as we discussed previously.
Drupal – Render a Block in PHP Code

This time, we want to render a view display by using the views_embed_view().

...
<?php print views_embed_view('<view name>', '<display id>', <argument>); ?>
...

 

In the above example, <view name> and <argument> are straight forward but for <display id>, you need to some tricky steps to figure it out.

First, go to the Views UI of the specific view and select the display which you want to embed. Then mouse hover on any items in Basic settings.

 

The <display id> is highlighted in red above.

Done =)

Reference:

2 thoughts on “Drupal – Render a View in PHP Code”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.