Created
April 9, 2014 09:10
-
-
Save augustyip/10245177 to your computer and use it in GitHub Desktop.
Drupal: Displays the output of a view, assumed to be a block display.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Displays the output of a view, assumed to be a block display. | |
* | |
* @param $view_name | |
* Machine name of the view. | |
* @param $display_name | |
* Machine name of the display within the view. | |
* @param $args | |
* (optional) Array of arguments for the view display. | |
* | |
* @return | |
* String containing the view output. If the view was empty, an empty string. | |
*/ | |
function module_display_view($view_name, $display_name, $args = array()) { | |
$output = ''; | |
// Load the view. | |
$view = views_get_view($view_name); | |
if ($view) { | |
// Override the URL so that exposed filters will work on blocks even without | |
// AJAX. | |
$view->override_url = current_path(); | |
$output = $view->preview($display_name, $args); | |
} | |
// Check for no content. | |
if (!strlen(trim(strip_tags($output)))) { | |
$output = ''; | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment