Discussions

Ask a Question
Back to All

Best way to use with_scope and params to filter content (Shop)

Hi,

what is the best way to filter with_scope and multiple params like category, color, size etc. and the case that maybe only one or two params are selected.

Example:
{% with_scope category: category, colors.in: [color], size.in: [size] %}...

When a user clicks on a category, no product appears. If i delete the colors.in and size.in it works.

My current workaround is:
{% assign category = params["category"] | default: '/^/' %}
{% assign size = params["size"] | default: null %}
{% assign color = params["color"] | default: null %}

and a lot of if.. else if.. else.. but i think there must be a cleaner approach

Thanks