Hide a tab if its pane is empty.
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | panels-hide_empty_panes-216076-51.patch | 694 bytes | agileware |
| #3 | panels_tabs.patch | 1.56 KB | robloach |
Hide a tab if its pane is empty.
| Comment | File | Size | Author |
|---|---|---|---|
| #51 | panels-hide_empty_panes-216076-51.patch | 694 bytes | agileware |
| #3 | panels_tabs.patch | 1.56 KB | robloach |
Comments
Comment #1
robloachAlthough it's not a patch, a simple if statement will hide the tab.....
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.
Comment #2
wim leersWhen/how are panes empty?
Comment #3
robloachYou 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....
Comment #4
wim leersWell, 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.
Comment #5
nath commentedIt would be nice to have this option.
Comment #6
cgjohnson commentedThis would be nice. Does it exist? Does it work for views without panels? Anyone have a suggestion about that?
thanks!
Comment #7
sdboyer commentedI'll have a look at this tomorrow, see if there's anything to be moved on here.
Comment #8
merlinofchaos commentedThis is not currently a patch against Panels.
Comment #9
wim leersEarl, 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.
Comment #10
merlinofchaos commentedIf the patch makes sense I agree that it could possibly be Panels responsibility to remove it before it gets to the style.
Comment #11
sdboyer commentedYeah, 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 :)
Comment #12
wim leersWell, if you want to support content-less panes, this won't work. In what cases do you you want/need that?
Comment #13
rgraves commentedI'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
Comment #14
sunBetter title. And, +1, we should support this.
Comment #15
tobiass commentedThis would be great. Subscribing
Comment #16
keesee commentedSubscribing
Comment #17
thelocaltourist commentedsubscribing
Comment #18
tsi commentedsubscribing
Comment #19
JStarcher commentedI 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.
Comment #20
rgraves commentedWhat 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.
Comment #21
bensemmel commentedSame issue for 6.x at http://drupal.org/node/208832
Comment #22
sunAccording to #614178-6: Panes with no values in view show up, after 3.2 upgrade, "something" was changed in 6.x-3.x, but I'm not sure what exactly, and, whether it actually solves this issue ;)
EDIT: I meant: I don't see a configuration option and I still get empty panes.
Comment #23
sunIn addition #400332: Hide mini panels when empty was marked as won't fix, since we cannot hide entire panels displays (although not sure whether we couldn't with some special-casing).
Comment #24
sunHrm, ok, it seems like 3.x-dev is indeed hiding empty panes. But as stated before, not mini panels that are used as panes in other panels.
My very very dirty workaround for now:
Comment #25
pathscollide commentedSubscribing.
I too am looking forward to this. I assume it will cover my use case:
Comment #26
merlinofchaos commented#25: Empty panes *are* being hidden. The issue, and this seems to be getting obscured repeatedly by a lot of people, is that some panes are not truly empty.
In the case of CCK, it's possible that it's putting markup (a div or span wrapper, for example) around an empty value. Thus the pane does not appear empty. In that case, there's nothing I can do to tell the pane is empty, CCK has to do that.
Comment #27
ayalon commentedI'm quite sure, that empty panes *Are* rendered.
I updated to the latest panels version and found the following:
In the old panels module was a function called theme_panels_pane().
It looked like that:
If a pane was empty NO output was rendered.
In the new current dev panels module, the theme function is preprocessed and works with a template. For themers this is much more convenient but:
There is no check in the code, to see if the pane is empty and therefore alle panes are rendered
I hope I could clarify this issue a bit.
Comment #28
aurelien-bordeaux commentedSuscribing
Comment #29
crea commentedI have view pane with empty view result (no nodes) in a minipanel. Before it was completely hidden, but after upgrade to the latest dev it randomly shows and disappears.
It's worth to note that I still have theme function and not template, and it generally works except the times when empty pane shows. Could it be that occassionally Drupal reverts to template instead of a function ? Should I switch to template because of that ?
Comment #30
crea commentedStrange. I disabled caching for that pane and problem went away.
Comment #31
sdboyer commented@crea - yeah...I need to spend some more time with the caching system:)
@ayalon - I'll take a look before our next release to see if I can't freshen up some of the logic here. Remember that if the content_pane itself has _anything_ in it (even empty markup), it WILL be output - so most of the complaints here have to do with individual plugins, not Panels itself.
Comment #32
damienmckennaExamples of where it happens for me:
(output from hook_panels_pane_content_alter()..)
The View does not have anything set for the "Empty text" option.
These are placed within a region in a mini panel which is then inside a term_view panel.
Comment #33
merlinofchaos commentedNote that having panes in a mini panel, and then displaying the mini panel, the mini panel will never be truly empty. There is markup that goes into making a mini panel and that is enough to trigger content. The mini panel is not currently capable of checking to see if all panes within the mini panel were empty.
Comment #34
damienmckenna@merlinofchaos: in the examples I provided the titles of the empty panes were showing when they shouldn't have been, not that the entire mini-panel itself should have been empty. One thing at a time ;-)
Comment #35
jeebsuk commentedI have a views block that is output through panels that has no extra html in it if it is empty, but the pane still renders if there is no content for the block. I thought this was because I was overriding the title through panels, but the empty pane is still present in the html even after I turned off overriding the title. So as far as I can see this problem still exists.
Comment #36
ianchan commentedsubscribe
Comment #37
Ofer Morag commentedSubscribing
Comment #38
dman commentedUnderstood. This is what I'm looking at. My mini panel contained some views, all of them empty in some contexts, yet always displaying the title of the mini panel. Fair enough.
Is this the sort of thing that should be then managed through 'visibility settings' for the element? I looked at that, but couldn't see how to use even php code to peer into the content of the mini-panel. ... probably because this 'visibility' check runs (efficiently) before the content of the mini-panel is built.
Hm.
For now I'll just make sure my view returns friendly empty text.
It appears it can be done with a theme hack also (as above), though I'd rather remove it with logic.
Perhaps it's the mini-panels job to return NULL (not even title or markup) if it detects that none of its content rendered anything. Optionally.
Comment #39
fehin commentedsubscribing
Comment #40
merlinofchaos commentedThe visibility settings run before the mini panel content is rendered, so while they could be used to not show the panel if it won't have content, it can't hide the panel if it doesn't have content, if that makes sense.
Comment #41
dman commentedI did something a bit evil. I used the output of the view - that was inside my mini-panel and sometimes empty - to hide its parent element (the whole mini-panel) with css when no results were found.
The 'empty text' message instead of saying "there are no results" now says:
This is weird, and probably won't scale to a mini-panel that has several empty panes, but fixes this for me today. My mini-panel was two versions of the same view (1 feature and three summaries of items in the same queue) so I know if the top is empty the remaining pane is empty also.
Don't try this at home.
Comment #42
merlinofchaos commentedOk, empty panes have not actually been fully hidden depending upon the style chosen, which certainly is part of the problem. I've increased the vigilance on hiding empty panes. Now, legacy region styles can still render empty panes if they want, but they're legacy so they need to be updated anyway.
Comment #43
dman commentedNice. Thankyou!!
Comment #45
glennnz commentedThis isn't working for me at all.
Have today upgraded to the dev version of Panels and Ctools, but my empty mini panels are still showing, using a custom style with shadow.
The particular mini panels I'm trying to hide are ones created through hook_ block(), not with a View... In particular, OG Group Details, and Ubercart Shopping Cart blocks.
Glenn
Comment #46
merlinofchaos commentedMini panels are never truly empty. Even if the pane inside a mini panel doesn't show, the mini panel itself still renders its layout. There's another issue about that, but right now the answer is that you just can't do that.
Comment #47
glennnz commentedOK, bugger.
Cheers
Comment #48
glennnz commentedA thought for a workaround.
Is it possible to add a conditional CSS class to the panel?
Somthing like:
Then I could style that new CSS to have no corners etc, and the same colour as my background, or a zero height, or hidden, or whatever.
UPDATE
Moved my thoughts to http://drupal.org/node/400332
Comment #49
Vote_Sizing_Steve commentedWill hiding through css lower my seo?
Comment #51
agileware commentedSorry to open this again, but cck field panes still don't work.
This is because cck field panes contain the comment < !-- /content-field -- > with some whitespace when they are empty.
I know you mentioned in #26 that this is cck's job but this patch fixes the issue for me, but I'm not sure if you want to do this sort of check?
Also, I'm no panels expert so it is very possible this check might need to be in other places as well.
Is this a method that would be acceptable?
Comment #52
agileware commentedActually, now that I'm thinking about it, it's probably a bug in cck that the comment is there when the field is empty.
Comment #53
agileware commentedSorry, I jumped the gun a bit.
It turns out my base theme was overriding the cck field template and adding that comment.
Comment #54
coolhandlukek2 commentedsubscribing
Comment #55
agileware commented@coolhandlukek2:
This has already been fixed.
I reopened it as I thought there was still a problem but the problem was with my theme, not panels.
Comment #56
mcpuddin commentedSince mini panels are never empty, here is an idea that worked for me:
1) Copy and paste panels-pane.tpl.php into my theme directory
2) Place the following condition around everything:
This can be a potentially dragging in performance based off of how long your content takes to go through strip_tags. I'd love to here of any thoughts on this approach.
Comment #57
Vote_Sizing_Steve commentedI found that http://drupal.org/project/panels_three_four_layout offered a decent work-around, in most situations.
Comment #58
bryancasler commentedsubscribing for a D7 solution
Comment #59
drupalok commented#56 works for me... thanks mcpuddin!
Comment #60
marc angles commentedHi,
I use 6.x-3.10,
I add some fields in a panel and I still see the pane even if the field is empty. The only way I can hide it is if I use the style "No markup at all".
All other styles show the empty field.
I simply don't get why there is so much debate on how Panels should work by default. It should work as drupal works: NO F* empty field is showed up ! and if you want to show them, just write code ;)
What am I missing ?
Comment #61
merlinofchaos commentedSwearing.
Comment #62
babruix commentedFor D7:
1) copy panels-pane.tpl.php into site theme templates directory
2) at the start of file, before output of panes layout, add this:
3) also could be handy for performance purposes to check $pane->type and $pane->subtype to ensure you`re on correct place,
or if you want this check only in one pane, create template for your pane - by renaming template to:
panels-pane--[pane type]--[pane subtype].tpl.php
read more How to figure out the appropriate name for your panels template
Comment #63
TravisJohnston commented^^ doesn't work properly. Hides panes that contain only images only. All other empty panes still show.
Comment #64
TravisJohnston commentedThere is a .panels-ipe-empty-pane class though that is included if .panels-ipe-portlet-content is empty, though its weird to have that class appear there, and not at the parent element of the panel itself. Since many themers will go off of the parent/top level element, it makes more sense to place that class there.
So it should be at the top level like so:
<div id="panels-ipe-pandid-15" class="panels-ipe-portlet-wrapper panels-ipe-portlet-marker .panels-ipe-empty-pane">Or else your still loading in the Panels html which there is no reason for.
Comment #65
TravisJohnston commentedSince I can't wait for a patch, for now I just did it with jQuery, checking to see if the panel contains the empty class, it places a 'hideme' class at the parent level and I have it set to display:none
$('.panels-ipe-portlet-wrapper.panels-ipe-portlet-marker:has(.panels-ipe-empty-pane)').addClass('hideme');Comment #66
merlinofchaos commentedIf you're using the IPE, there is a placeholder for empty panes that shows up, which is why there is that panels-empty-pane class. They shouldn't appear normally until the IPE is actually enabled, but it's possible that your CSS is making them appear anyway.
If you manage to make the pane disappear entirely, then when someone uses the IPE and maniplates the panel, that pane could get deleted inadvertently.
Comment #67
TravisJohnston commentedHello @merlinofchaos,
I will check to see if its a problem. I am doing this in Drupal Commons and specifically on the User Profile pages, if a user doesn't have information to place in one of the panel fields, a empty skinny white box appears. The CSS is just giving it the color, width, etc. the HTML shows up regardless and this is how Acquia setup Commons apparently. So it made sense to invoke a higher level rule to hide the entire panel when empty.
The more I think about it though is, yes the IPE is on so you can customize pages, but I am going to lock down the user pages anyways so they only contain certain feeds so I can just specify my element with .page-user in the beginning so it doesn't mess up other areas. I haven't really seen an issue on other pages so I think this will work.
Comment #68
Anonymous (not verified) commentedThere is an easy way to do this without having to manipulate code. In the view page or pane, add the filter image:delta = IS NOT EMPTY. This carries over to panels. Saved me hours of headaches. ;)