1

Programmatically, How to check if view result is not empty with in custom function? I want to check the views result is it empty or not, and then display the result. How can i do?

use Drupal\views\Views;
use Drupal\views\ViewExecutable;

$view = Views::getView($view_name = "My View");
$view->setTitle('Sample Title');
$view->setArguments($args = ['all']);
$view->display_handler->setOption('empty', $empty = 'No content');
$view->preExecute();

// Need to check if empty result, before render

$markup = $view->render();
2
  • 4
    use $view->execute(); and if (!empty($view->result)) { ...
    – No Sssweat
    Jun 21, 2021 at 8:23
  • Yes, it's working fine. Jun 21, 2021 at 8:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.