Hide empty panes
Rob Loach - January 30, 2008 - 22:45
| Project: | Panels |
| Version: | 5.x-2.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
Hide a tab if its pane is empty.

#1
Although it's not a patch, a simple if statement will hide the tab.....
<?php
foreach ($panes as $pane_id => $content) {
// Only show the tab if there is existing content
if ($content->content) {
// Remove the title from the content. We don't want titles in both the tab
// and the content associated with the tab.
$content_without_title = drupal_clone($content);
unset($content_without_title->title);
$tabs[$id][$pane_id] = array(
'#type' => 'tabpage',
'#title' => $content->title,
'#content' => theme('panels_pane', $content_without_title, $display->content[$pane_id], $display),
'#weight' => $index,
);
$index++;
}
}
?>
This will effectively show the tab only if content exists within it. I would love to make a patch, but I'm quite busy at the moment.
#2
When/how are panes empty?
#3
You can have an empty pane if you're displaying a view that queries some nodes that don't exist and the view doesn't have its "Empty Text" set. In Panels (with a normal panel), when this happens, the pane just doesn't display. With Panels Tabs, it displays an empty tab. This could be considered a bug in Panels Tabs and is fixed with this patch.
We could move this into a style setting it you want....
<?php$form['hide_empty_tabs'] = array(
'#type' => 'checkbox',
'#title' => t('Hide empty tabs'),
'#description' => t('This option will hide tabs that do not contain content.'),
'#default_value' => (isset($style_settings['hide_empty_tabs'])) ? $style_settings['hide_empty_tabs'] : FALSE,
);
?>
#4
Well, just about every style would have to implement this feature. So perhaps it's better if we can do this in Panels itself. Moving to the Panels issue queue, to get some feedback about this from merlin.
#5
It would be nice to have this option.
#6
This would be nice. Does it exist? Does it work for views without panels? Anyone have a suggestion about that?
thanks!
#7
I'll have a look at this tomorrow, see if there's anything to be moved on here.
#8
This is not currently a patch against Panels.
#9
Earl, the issue at hand is whether each panel style should check for itself if a pane is empty and then not render it, or if Panels itself should handle this. If you decide it's the former, then I'll move it back to the panels_tabs issue queue and fix it.
#10
If the patch makes sense I agree that it could possibly be Panels responsibility to remove it before it gets to the style.
#11
Yeah, I think this is legit, although it's also a bit complicated, as I've had some reasonably-argued requests for allowing content-less panes to be rendered in particular ways, too.
Ultimately, though, I'd be most interested to see a patch that actually pertains to Panels :)
#12
Well, if you want to support content-less panes, this won't work. In what cases do you you want/need that?
#13
I've been using the patch suggestioned in comment #1 to solve my problem with empty tabs appearing. It worked, however I have about 40 views that are used with my panel to create tabs. No page uses all 40 views - some use 2 of the views, some use 4, etc.
The problem is with this fix it runs the sql queries for all 40 views and then uses the IF statement to decide whether to display it or not. This makes the page loading very slow.
Is there a way that I can have it only run the sql queries if it knows there is content for that view? That way it would only run the necessary queries for the tabs it will be displaying.
Rob
#14
Better title. And, +1, we should support this.
#15
This would be great. Subscribing
#16
Subscribing
#17
subscribing
#18
subscribing
#19
I was going to use this patch but with the problem Rob is talking about I don't think I will even try it. I have 40+ views as well.
#20
What I ended up having to do was create separate panels for each of my pages, then only add the views (tabs) that were necessary for those panel pages. It was an administrative headache to set them all up because there are so many panel pages, but it drastically improved the speed for the end user. If you don't have many views, the patch above worked great. If you have dozens of views, consider using separate panels for each page.
#21
Same issue for 6.x at http://drupal.org/node/208832