Developer forum

Forum » Ecommerce - Standard features » How can I loop "empty" facets

How can I loop "empty" facets

Hans Ravnsfjall
Hans Ravnsfjall
Reply

The problem is that my current facets loop, only shows facets that have values. That's fine as long as there is 1 or +1 results. But not what I want when there is no result, because I want the user to get the option of selecting all options/facets (eg. all "empty" facets)  - while their current selections are still "active" in the filter.

 


My loop dows not include empty facets, but maybe someone has a suggestion on how I can get "empty" facets included?

my code looks like this.


      
@foreach (LoopItem facet group in GetLoop ( "Facet Group"))
{
        foreach (LoopItem facet in facetGroup.GetLoop ( "Facets"))
        {
           
                <Div class = "col-md-3">
                  <Label for = "district"> @ facet.GetString ( "Facet.Name") </ label>
                    <Select multiple class = "e1" name = "@ facet.GetString (" Facet.QueryParameter ")" ID = "@ facet.GetString (" Facet.QueryParameter ")" style = "width: 100%;">
                  
                        @foreach (LoopItem option in facet.GetLoop ( "Facet Options"))
                        {
                            was option.GetValue value = ( "FacetOption.Value");
                            was selected option.GetBoolean = ( "FacetOption.Selected");
                            was option.GetString label = ( "FacetOption.Label");
                            was count = option.GetInteger ( "FacetOption.Count");

                            <Option value = "@ value" selected = "@ selected">
                                @label (@count)
                            </ Option>

              
                        }
                    </ Select>
</ Div>
          
        }
}

 
 
 

Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Hans

There is a setting on the catalog paragraph you can check out and see if it fixes it. "Include empty facets" or something like that.

Have a nice weekend, Nicolai

Votes for this answer: 1
 
Hans Ravnsfjall
Hans Ravnsfjall
Reply

Thank you Nicolai

exactly what I was looking for :)

A very nice weekend to you to :)

 

br,

Hans

 

You must be logged in to post in the forum