Community Documentation

Embedding an exposed form filter

Last updated June 23, 2012. Created by grndlvl on June 23, 2012.
Log in to edit this page.

<?php
/**
* Returns the exposed filter widgets for a view.
*
* @param mixed $view
*  Either a string with the name of the view or an object of the view
* @param string $display_id
*  An optional string with the name of the display for the view.
*
* @return string
*  The themed exposed filter form.
*/
function embed_views_exposed_form($view, $display_id = '') {
?>

To figure out the id of a display, look under Other, in the
view edit page for the particular view that will be embedded, for
Machine Name what ever this name is is what should be used
for the $display_id variable.

Usage

Simple version of code to embed an exposed filter.

<?php
 
print embed_views_exposed_form('test', 'embed_1');
?>

Embedding a view's exposed form for an alrady created view using the
embed_views_exposed_form() helper function.

<?php
  $view
= views_get_view('test');
 
$view->set_display('embed_1');
  print
embed_views_exposed_form($view);

  ...
some other code ...

 
$view->destroy();
?>

Embedding a view's exposed form for an already created view using the
display's embed_views_exposed_form() helper method.

<?php
  $view
= views_get_view('test');
 
$view->set_display('embed_1');
  print
$view->display_handler->embed_views_exposed_form();

  ...
some other code ...

 
$view->destroy();
?>

About this page

Drupal version
Drupal 7.x
Audience
Programmers
Level
Advanced
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.