Hi

I'm having problems trying to show the node header with zero results views. In short, I'd like to get:

View header text
View exposed filters
View empty text
View footer

But instead I get:

View exposed filters
View empty text
View footer

Am I missing something or is there any workaround for this?

Thanks in advance ;)

Comments

jroth’s picture

I had the same issue. I solved it by removing lines 1531 and 1533 from the theme_views_view function in views.module. Hope this helps.

// if ($num_nodes) {
$output .= views_get_textarea($view, $type, 'header');
// }

merlinofchaos’s picture

You hacked a theme function? You ought to be ashamed of yourself for telling people that. Theme functions are overridable. =(

jroth’s picture

Please forgive my apparent ignorance here. I am a drupal noob. What do you mean "Theme functions are overridable"? Is there a better way to do this?

merlinofchaos’s picture

Status: Active » Fixed

Yes, it is possibly Drupal's single most important feature. =)

See: http://drupal.org/node/55126

Though you do have the right direction. If you override that theme function by and make the modification you suggest in your theme, you get the desired result.

jroth’s picture

merlinofchaos, thanks for all the help! It is working beautifully and (most important) correctly now. :-)

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

ghing’s picture

Here is my workaround for Views 6.x-2.5, just to help others. I overrode template_preprocess_views_view in my template.php

/**
 * Preprocess the primary theme implementation for a view.
 *
 * This is an override of the function provided with the views module in
 * views/theme/theme.inc.  Our version always shows the view header, even if there
 * are no results for specified views.
 */
function phptemplate_preprocess_views_view(&$vars) {
  $view = $vars['view'];
  $always_show_header = array('page_assignments');
	
	// The default views behavior is to hide the header if there are no items
	// in the view.  We want to override this and always show the header in
	// some cases.
	if (in_array($view->name, $always_show_header)) {
	  $vars['header'] = $view->display_handler->render_textarea('header');
	}
}
merlinofchaos’s picture

In Views 2 there is a checkbox in with the header that you can use. NO need for that code. :P

hixster’s picture

Is it possible to show the view header ONLY if the view returns no results. It would be a handy option.
That way the header (or footer) could be used to display useful message like : "your search returned no results, please search again"

NoRandom’s picture

Yes, you can count the results number and using a php header you could do something like:

<?php
    $view = views_get_current_view();
    if ($view->total_rows    == 0){
       print 'your custom html header here';
       }
?>

*code not tested, just written what I remember.

Anyway, why would you want to do that?

I mean you can write this message in the empty text field. Then, check the options "show header/footer even if view has no results" and you'll get the same output without any line of code.

Regards.

UPDATE: Sorry, I didn't notice this issue was for 5.x version wich I think doesn't contain the empty view header option.