The Embed Views Display
If you don't know about embedding views you might want to check out this post first http://views-help.doc.logrus.com/help/views/embed.
Update - This is now a module that you can download on d.o.
Have you ever created a view and the only thing you needed it for was embedding it somewhere on your site? On some projects I have had recently I certainly had and embedding regular view displays will work. But, you either have to choose from a block, page, feed, or use the default display from the views you want to embed. What if you did not want to have a callback or a block associated with a view and only wanted to embed it somewhere else on the site? What could you do? Create an embed views display of course!
The whole purpose of this views display is to only create a default style views display that does not have any additional features or "cruft".

What I ended up doing since I wanted it to act exactly like the views default display was replicate the display and let it know it is not the default and give it another name and it worked!
If you would like to have your own just follow the steps below.
Requirements
- Drupal 6.x
- Views 2
First, create the module that will contain the information necessary for integrating w/ views2. Lets call it my_views.
Your file layout should look like.
- my_views
- my_views.module
- my_views.info
- my_views_plugin_display_embed.inc
The module only has to implement one function, hook_views_plugins().
<?php /** * Implementation of hook_views_plugins */ function my_views_views_plugins() { return array( 'display' => array( 'embed' => array( 'title' => t('Embed'), 'help' => t('Creates a display specifically for embed.'), 'handler' => 'my_views_plugin_display_embed', 'theme' => 'views_view', 'use ajax' => TRUE, 'use pager' => TRUE, 'use more' => TRUE, 'accept attachments' => TRUE, 'help topic' => 'display-pane', ), ), ); } ?>
The my_views_plugin_display_embed.inc file should look something like.
<?php // $Id:$ /** * @file * Contains the embed display plugin. */ /** * A plugin to handle defaults on a view. * * @ingroup views_display_plugins */ class my_views_plugin_display_embed extends views_plugin_display { /** * Determine if this display is the 'default' display which contains * fallback settings */ function is_default_display() { return FALSE; } /** * The default execute handler fully renders the view. * * For the simplest use: * @code * $output = $view->execute_display('default', $args); * @endcode * * For more complex usages, a view can be partially built: * @code * $view->set_arguments($args); * $view->build('default'); // Build the query * $view->execute(); // Run the query * $output = $view->render(); // Render the view * @endcode * * If short circuited at any point, look in $view->build_info for * information about the query. After execute, look in $view->result * for the array of objects returned from db_query. * * You can also do: * @code * $view->set_arguments($args); * $output = $view->render('default'); // Render the view * @endcode * * This illustrates that render is smart enough to call build and execute * if these items have not already been accomplished. * * Note that execute also must accomplish other tasks, such * as setting page titles, breadcrumbs, and generating exposed filter * data if necessary. */ function execute() { return $this->view->render($this->display->id); } } ?>
And don't forget the info file.
; $Id:$ name = My Views description = Defines embed view display. core = 6.x





How do you display the view?
The answer to this may be obvious to a Drupal expert, but I am a Drupal novice, and I am at a loss. I have installed the embed_views module and created a view to be embedded. I want to embed the view inside a page. How do I do it? The link above to http://views-help.doc.logrus.com/help/views/embed is no help to me as it does not tell me either where to put the function, or, more importantly, what the functionality of the function is. Are you able to help me?
Thanks,
Matt.
Template files
This is great, however the template files don't seem to be getting picked up. I want to use a stripped down views-view--embed.tpl.php file for embedded views but it's not being included. It still utilizes the default views-view.tpl.php. Any ideas.
After poking around for about
After poking around for about 45 mins I am unable to remedy this issue :(. If I were to change the 'theme' attribute inside the hook_views_plugins it is expecting an implementation of hook_views_data(), which will "Describe table structure to Views."(views/docs/docs.php) Not something we really want to do...
If you find anything please let me know.
Thanks,
Jonathan
I was poking around too
There is so much going on with views and I don't have the time to learn all the details right now. I was looking at the calendar module to see how it was done there, but that's way too much code to look at right now. Thanks!
I must be doing something wrong.
1. I built the module, enabled it, created a new view and added a Page display. No problem.
2. Then I added an Embedded display and I got this JavaScript alert: "An error occurred at /admin/build/views/ajax/add-display/test." ("test" is the name of my view.)
3. I then try to add a Block and I get the same error - so apparently something in the JS gets hosed. I hit reload and I get a white screen.
Hrmm thats really strange I
Hrmm thats really strange I got a fresh Drupal 6 install w/ Views 6.x-2.5 and tested it out, worked fine for me.
Which versions of Views and Drupal are you using?
Also check the name of the include you made that contains the plugin because it must be the name of the handler class that you specified in hook_views_plugins() in order for Views to pick it up.
Thanks,
Jonathan
Yeah, I triple-checked the
Yeah, I triple-checked the naming with no luck. So then I thought I'd give the the module a whirl (http://drupal.org/project/embed_views) and it worked as expected. Thanks!
Great! Glad it worked out for
Great! Glad it worked out for you.
I've had the same problems
Excelent idea here, very useful!
I think it might even be worth to include with views perhaps? have you proposed it? if not, then it'd be handy if you started a drupal project for it... thoughts?
I had thought about doing
I had thought about doing that. I might open a post on d.o. If I do I will post a link back here.
What happens with exposed filters?
What happens if you have exposed filters and filter the list. Does the page it is embedded in reload with the appropriate filter?
Here is a great explanation
Here is a great explanation of exposed views and exposed filters http://drupal.org/node/156130.
It would act the same as any
It would act the same as any other view display. It would not take away native features of views such as arguments, sorting, filters, or exposed filters.
finally
I was looking for the exact same view display type to use with quicktabs and insert_view. (http://drupal.org/node/373115) If you add it to d.o I would use it.
Pasqualle
There is now an official
There is now an official release on d.o http://drupal.org/project/embed_views.
Thanks,
Jonathan
But what does it do?
I might have missed something, but what does it do? You say you embed it, but since you have selected no fields to display, what does it output when you render it?
Yeah sorry about that... the
Yeah sorry about that... the screenshot does have a very useless view... Did not think about that. But, yeah it is just there to show you where you can expect the views embed display to show up.
I think it creates neither
I think it creates neither page nor block which means for page you don't have to specify an URL, you don't get additional block in Site Building > Block, etc. Just a plain view which you can then use with Views Reference or View Insert or any other module which lets you display a view in certain place. Pretty nice, thank you for this!
Yeah exactly!
Yeah exactly!