Hide a tab if its pane is empty.

Comments

robloach’s picture

Status: Active » Needs review

Although it's not a patch, a simple if statement will hide the tab.....

  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.

wim leers’s picture

When/how are panes empty?

robloach’s picture

StatusFileSize
new1.56 KB

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....

  $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,
  );
wim leers’s picture

Project: Panels Tabs » Panels
Version: 5.x-1.x-dev » 5.x-2.x-dev

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.

nath’s picture

It would be nice to have this option.

cgjohnson’s picture

This would be nice. Does it exist? Does it work for views without panels? Anyone have a suggestion about that?
thanks!

sdboyer’s picture

I'll have a look at this tomorrow, see if there's anything to be moved on here.

merlinofchaos’s picture

Status: Needs review » Active

This is not currently a patch against Panels.

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

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.

merlinofchaos’s picture

If the patch makes sense I agree that it could possibly be Panels responsibility to remove it before it gets to the style.

sdboyer’s picture

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 :)

wim leers’s picture

Well, if you want to support content-less panes, this won't work. In what cases do you you want/need that?

rgraves’s picture

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

sun’s picture

Title: Hide Empty Tabs » Hide empty panes
Status: Postponed (maintainer needs more info) » Active

Better title. And, +1, we should support this.

tobiass’s picture

This would be great. Subscribing

keesee’s picture

Subscribing

thelocaltourist’s picture

subscribing

tsi’s picture

subscribing

JStarcher’s picture

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.

rgraves’s picture

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.

bensemmel’s picture

Same issue for 6.x at http://drupal.org/node/208832

sun’s picture

Version: 5.x-2.x-dev » 6.x-3.2
Component: User interface » Code

According 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.

sun’s picture

In 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).

sun’s picture

Hrm, 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:

/**
 * Implements hook_panels_pane_content_alter().
 *
 * Dirty hack to hide empty mini panels.
 */
function custom_panels_pane_content_alter(&$content, $pane, $args, $context) {
  if ($content->module == 'panels_mini' && drupal_strlen($content->content) < 150) {
    $content = FALSE;
  }
}
pathscollide’s picture

Subscribing.

I too am looking forward to this. I assume it will cover my use case:

  • I have a custom content type with a "Summary" field.
  • Some instances of that type have content in the "Summary" field, others don't
  • I'm using a Panels pages variant to control the way nodes of this type are displayed. One pane contains the Summary field and a pane style (e.g. Rounded corners) is applied to it.
  • When that field contains no content, I don't want that particular pane to appear (currently, an empty pane with rounded corners is showing up).
merlinofchaos’s picture

#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.

ayalon’s picture

I'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:

function phptemplate_panels_pane($content, $pane, $display) {
  if (!empty($content->content)) {
  
  code goes here......

  }

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.

aurelien-bordeaux’s picture

Suscribing

crea’s picture

I 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 ?

crea’s picture

Strange. I disabled caching for that pane and problem went away.

sdboyer’s picture

Assigned: Unassigned » sdboyer

@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.

damienmckenna’s picture

Examples of where it happens for me:

(output from hook_panels_pane_content_alter()..)

... (Object) stdClass
  type (String, 5 characters ) views
  subtype (String, 21 characters ) [view-name]
  original_title (String, 0 characters )
  title (String, 24 characters ) [view-title]

The View does not have anything set for the "Empty text" option.

... (Object) stdClass
  module (String, 9 characters ) term-list
  subject (String, 11 characters ) Child terms
  delta (String, 5 characters ) child
  type (String, 9 characters ) term_list
  subtype (String, 9 characters ) term_list
  original_title (String, 0 characters )
  title (String, 11 characters ) Child terms

These are placed within a region in a mini panel which is then inside a term_view panel.

merlinofchaos’s picture

Note 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.

damienmckenna’s picture

@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 ;-)

jeebsuk’s picture

I 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.

ianchan’s picture

subscribe

Ofer Morag’s picture

Subscribing

dman’s picture

Note 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.

Understood. 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.

fehin’s picture

subscribing

merlinofchaos’s picture

The 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.

dman’s picture

I 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:

<!-- cannot hide mini-panels through code. Sneak in a hide fix for when there is no content --> 
<style type="text/css"> 
.pane-latest-section-charts{ display:none; }
</style> 

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.

merlinofchaos’s picture

Status: Active » Fixed

Ok, 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.

dman’s picture

Nice. Thankyou!!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

glennnz’s picture

Status: Closed (fixed) » Active

This 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

merlinofchaos’s picture

Status: Active » Fixed

Mini 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.

glennnz’s picture

OK, bugger.

Cheers

glennnz’s picture

A thought for a workaround.

Is it possible to add a conditional CSS class to the panel?

Somthing like:

<?php
if (!$content->content) {
  some funky code here which changes the css of the particular panel;
}
?>

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

Vote_Sizing_Steve’s picture

Will hiding through css lower my seo?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

agileware’s picture

Version: 6.x-3.2 » 6.x-3.x-dev
Status: Closed (fixed) » Needs review
StatusFileSize
new694 bytes

Sorry 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?

agileware’s picture

Actually, now that I'm thinking about it, it's probably a bug in cck that the comment is there when the field is empty.

agileware’s picture

Status: Needs review » Closed (fixed)

Sorry, I jumped the gun a bit.

It turns out my base theme was overriding the cck field template and adding that comment.

coolhandlukek2’s picture

subscribing

agileware’s picture

@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.

mcpuddin’s picture

Since 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:

  <?php if (trim(strip_tags($content))): ?>
    ..... EVERYTHING ELSE ......
  <?php endif; ?>

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.

Vote_Sizing_Steve’s picture

I found that http://drupal.org/project/panels_three_four_layout offered a decent work-around, in most situations.

bryancasler’s picture

subscribing for a D7 solution

drupalok’s picture

#56 works for me... thanks mcpuddin!

marc angles’s picture

Status: Closed (fixed) » Active

Hi,
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 ?

merlinofchaos’s picture

Status: Active » Closed (won't fix)

Swearing.

babruix’s picture

Version: 6.x-3.x-dev » 7.x-3.3
Assigned: sdboyer » Unassigned

For 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:

<?php
// Hide panes with empty content
if(!trim(strip_tags(render($content)))) {
  return;
}
?>

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

TravisJohnston’s picture

^^ doesn't work properly. Hides panes that contain only images only. All other empty panes still show.

TravisJohnston’s picture

There 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.

TravisJohnston’s picture

Since 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');

merlinofchaos’s picture

If 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.

TravisJohnston’s picture

Hello @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.

Anonymous’s picture

There 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. ;)