If the view inside the view field is empty the field does not get excluded (hidden).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pontus_nilsson’s picture

This can be solved by adding a template file for the view that is added as a field to your view that strips out the surrounding div for the view.

Damien Tournoud’s picture

Title: Hide field if empty » Add an option to hide the field if the child view returns no result
Version: 6.x-1.0-beta1 » 7.x-1.x-dev

Retitling, bumping.

This module uses views_embed_view() directly. It should be easy to render the view ourselves and add the option to not return anything if the child view has an empty result set.

Damien Tournoud’s picture

Category: bug » feature

This is technically more a feature request.

the_paulus’s picture

Here is how I got around the problem. I created a module and added this function:

function MODULE_views_post_render(&$view, &$output, &$cache) {
if($view->name == 'VIEWNAME') {
if(count($view->result) == 1) {
$output = '';
$cache = '';
}
}
}

For my view field I created a view and am only using the default display. If you have a view with multiple display, you're going to have to add additional logic to make sure you are not removing anything you want to keep.

davidarthur’s picture

It should just use the "Hide if empty" option.

Anyone got a better solution yet? I'm looking into it...

(This bug is for v6 release also)

pbeakley’s picture

+1

damiankloip’s picture

Status: Active » Fixed

Committed to dev branch, as per #2, views_embed_view is not being used anymore.

Status: Fixed » Closed (fixed)

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

moniuch’s picture

Even though the issue has been closed, let me chime in.
I got here because I too have been suffering from lack of this 'hide if empty' feature, implemented on the UI side, just like modules are supposed to, without any workarounds. And I was surprised to see the status 'closed (fixed)' - I can't see the feature, so how should I understand that?

damiankloip’s picture

This is referring to the Hide if empty checkbox under 'No results behaviour' settings for the field. Where are you looking for this feature? I'm pretty sure it's there.

moniuch’s picture

I was looking in the Manage Display and Manage Fields form for the content type where I'm inserting the view.
Utilizing the view I'm displaying other categories that a node is tagged with. If there is no other association than the current one, I meant to hide not only the result, but also the label of the view field. I thought the visibility should be controlled on the node level.
The "Hide if empty" checkbox is there in the View but does not cause the label to go off when checked.
Please enlighten me as per the logic you implemented.

damiankloip’s picture

Hang on, you are embedding the view in a node? So you aren't using this module to do it?

moniuch’s picture

Grrrh.... Looks like I have confused Viewfield with VFV... Will you ever forget? How can I redeem my sin?

damiankloip’s picture

Ha, :) Thought something strange was going on. I will heal over time.....

ice5nake’s picture

Status: Closed (fixed) » Active

I'd like to see something happen surrounding this request. My take on this was Views Field View is not working correctly with the "Hide if Empty" and "Hide empty fields" View options.

FWIW, I'm using 6.x

damiankloip’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Changing the issue to the correct version is a good place to start. I would like to see something happen around this too, but unfortunately time is an issue. Most of my concentration is going into the 7.x branch at the moment. Patches are welcome.

jvieille’s picture

Views field still shows up even if it is empty.
Any solution yet?

fizk’s picture

Status: Active » Needs review
FileSize
1.99 KB

This patch seems to work for me.

fizk’s picture

Note that I removed the unset($options[$this->view->name]); in that patch because I needed to access the current view, but a different display.

fizk’s picture

Changed a comment to "// If there are no results and either hide_empty is set or the empty text is set."

jibran’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Drupal 6 compatible versions of the module are not supported anymore.