embed.html 1.2 KB

123456789101112131415161718192021222324
  1. You can easily embed the results of a view into other parts of your site;
  2. either with code as a module, or in nodes or blocks as snippets. The
  3. easiest way is to use the function <strong>views_embed_view()</strong>:
  4. <code>/**
  5. * Embed a view using a PHP snippet.
  6. *
  7. * This function is meant to be called from PHP snippets, should one wish to
  8. * embed a view in a node or something. It's meant to provide the simplest
  9. * solution and doesn't really offer a lot of options, but breaking the function
  10. * apart is pretty easy, and this provides a worthwhile guide to doing so.
  11. *
  12. * @param string $name
  13. * The name of the view to embed.
  14. * @param string $display_id
  15. * The display id to embed. If unsure, use 'default', as it will always be
  16. * valid. But things like 'page' or 'block' should work here.
  17. * @param ...
  18. * Any additional parameters will be passed as arguments.
  19. */
  20. function views_embed_view($name, $display_id = 'default') {
  21. </code>
  22. To figure out the id of a display, hover your mouse over the tab to select that display. Everything after the '#views-tab-' is the id of that display. This ID is guaranteed never to change unless you delete the display and create a new one.