1

I have a view as follows:

  • Display: Master
  • Format: Unformatted list
  • Fields: Content: Images
  • Filter criteria: Content type, published
  • Contextual filter: Content: Nid with 'Provide default value' set to 'Content ID from URL'

The view is placed on the node using Panels and Panalizer modules.

The node in question had no images uploaded to the image field but the view is outputting an empty row as follows:

<div class="view view-case-study-images view-id-case_study_images view-display-id-default view-dom-id-0c286f7a769d643d2e0cf9709edc0c79">
  <div class="view-content">
    <div class="views-row views-row-1 views-row-odd views-row-first views-row-last"> </div>
  </div>
</div>

I have checked and unchecked the 'Count the number 0 as empty' and ' Hide if empty' on the 'Content: Images' field but the view still shows.

How can I hide the view (by removing this empty row) if there are no images on a node?

Happy to attach any additional information you require to this post. Thanks.

5
  • Add hide if empty in each fields. Dec 9, 2014 at 10:58
  • @SumitMadan as per above, I've already done this Sumit Dec 9, 2014 at 11:25
  • Actually I have also faced same problem many times. What I actually do just add a filter nid not empty. Dec 9, 2014 at 11:58
  • @SumitMadan There's no option to set Nid as not empty when adding it as a filter. Additionally, I believe the Nid will exist whether there are images or not because of the contextual filter. Dec 9, 2014 at 12:50
  • May be Nid != ''. Dec 9, 2014 at 12:54

2 Answers 2

2

You need to set a filter value on the image field.

Open your view, then edit as follows:

Enable 'Use Aggregation'.

Make sure that the image field is aggregating on 'Group Result together', using Group column 'Entity ID'. Sometimes views gives an error here, so just remove and re-add the image field with these settings.

enter image description here

Add a Filter criteria using 'field_image:fid', set its aggregation to COUNT, and choose the operator 'Is greater than' with value 0.

You might have to remove all of your sort criteria and re-add them as switching on aggregation mid stream can cause issues with sorting.

Basically, what you have done is to do a count on the image primary key (fid) for each node, and if the count is 0 to exclude the record from the result.

This should work for an image field that has either a single, or multiple values.

I you are uncomfortable working with aggregation, then have a look at the Field Count Formatter module. It adds a views field that simply count the number of values contained in a multi-value field. I would imagine it providing a filter in views as well.

1
  • Worked perfectly. Thanks. And yes, it's really important to either re-save or re-add your fields otherwise this won't work. Dec 9, 2014 at 15:00
0

May be the content is not NULL, but it is equal to '' (empty string) or ' ' (space) Try to add a filter on field "Images" and test for lenght >0 (or 1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.