Webflow CMS Filter Component: Setting Up Multi-Filter Type & Custom Code

Published on
May 4, 2020

How to Use Webflow CMS Filter Component

Webflow CMS has a powerful filter component that allows you to filter collection items based on the text inside the collection. In this guide, we are going to walk through how to set up the filter component in Webflow CMS, with a focus on the multi-filter type and the custom code needed to make it function properly.

Understanding the Filter Component

The filter component in Webflow CMS works by taking the text inside a collection item and using it to filter the items in the grid. Each piece of text inside the collection item can be used as a filterable option. For example, if you have a collection of items with tags like "2017," "2018," "red," "blue," "web design," etc., you can filter the items based on these tags.

Setting Up the Collection List

To start using the filter component, you need to have a collection list in Webflow CMS. Each collection item should contain the text that you want to use for filtering. This could be tags, categories, or any other relevant information.

Applying Classes to Elements

Once you have your collection list set up, you'll need to apply classes to the elements that will be involved in the filtering process.

  1. Collection List Class: Apply the class collection-list to the collection list element. This class is essential for the filter to work properly.

  2. Parent Wrapper Class: Next, create a parent wrapper that will hold the filter buttons. Apply a class, such as filters-wrapper, to this parent element.

  3. Data Attribute: Apply a data attribute, filter-by, to each filter button. This data attribute will be used to search for the text inside the collection item.

Making Filter Buttons Visible or Hidden

While the filter buttons need to be present in the published site, they don't necessarily need to be visible. You can choose to hide them on the published site. However, the filter will still work as long as the text is present inside the collection item.

Filtering with Multi-Filter Type

The multi-filter type allows you to check multiple options at once. For example, if you have filter options like "blue," "red," "yellow," "green," etc., users can select multiple colors and filter the collection items accordingly.

Custom Code Setup

Now let's move on to the custom code that's required to make the multi-filter type work with the filter component in Webflow CMS.

  1. F and Sweet CMS Library Script: Before the closing body tag, you need to add the F and Sweet CMS library script. This script is responsible for enabling the filter functionality.

  2. Project-Specific Script: You'll also need to create a project-specific script where you'll write the code to initialize the filter component and define the filtering rules.

  3. Creating a New Instance: In the project-specific script, you'll start by creating a new instance of the F and Sweet library and targeting the collection-list class.

  4. Defining Filter Groups: Next, you'll define an array that specifies the filter groups you want to filter by and how to filter by them. This array should include the parent wrapper, filter type (in this case, multi), and any additional styles or animation effects.

  5. Running the Filter Component: Finally, you'll run the filter component on the collection list grid by passing in the filter array that you've just defined. This will enable the multi-filter functionality based on the specified filter groups.

Conclusion

Using the filter component in Webflow CMS is a powerful way to allow users to dynamically filter collection items based on specific criteria. By understanding how to set up the collection list, apply classes to elements, and write the necessary custom code, you can create an interactive and user-friendly filtering experience for your website visitors. With the multi-filter type, users can select multiple options and see the collection items get filtered in real-time, providing a seamless browsing experience.