0

I have a view which has 5 menu tabs. I want to hide the tab if it doesn't have any results. Can anyone please help me with the suggestions.

1

2 Answers 2

0

Can be done with Jquery Check for the class "view-empty", if this div has inner div, then that means it has some content, if not hide that parent tab div.

0

By implementing hooks as below

function custom_tabs_hide_menu_local_tasks_alter(&$data, $route_name, $route_match) {

// Check if the current route matches the route where your Views is being displayed.

if ($route_name === 'entity.view.your_view_id.page_1') {

// Replace 'your_view_id' with the actual ID of your view.
// Check if the View has no results.

$view = \Drupal\views\Views::getView('your_view_id'); 

// Replace 'your_view_id' with the actual ID of your view.

$view->setDisplay('page_1'); // Replace 'page_1' with the display ID of your view.

$view->execute();

if (empty($view->result)) {
  // Hide the tab.
  unset($data['tabs']['view-id.your_view_id-page_1']);
}

} }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.