Drupal - Get View Display Id

in

Q: How do I get the 'display id' ($display_id) of a view display so that I can pass it to views_embed_view() when programmatically showing a view?

A: View display ids follow a pattern like page_1, page_2, block_1, block_2 etc., depending on the display type - they do not follow the display's title (I spent a lot of time trying to plug in variations of the display name with no success!) The documentation for views_embed_view() does not explain what the display id is or where it comes from....

There is a simple way to figure out what it is. Navigate to your view in the Views UI, make sure your display is active by clicking on it and then hover your mouse over one of its settings (for example, its title) - the display id will now be displayed at the bottom of the browser as part of the link url, for example:

Here 'page_1' is the display id and can be passed to
views_embed_view() as follows:

  print views_embed_view('user_horses', 'page_1');

So, you can either get it this way, or just guess it if you manage to remember the page_1, page_2, block_1, block_2...... pattern (which I can never do even though it's very simple!).

Stranger
Stranger's picture
Thanks!

I was looking all over for this!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Pride on FacebookPride on TwitterPride on TwitterPride on Twitter

Join Our Newsletter

* indicates required

Irish Internet Association

finalist.png
phone-number.png