How to display data from external API in Webflow - Part 3 - Filter content with faceted search
In this guide, we'll walk through the process of creating a faceted search feature that allows users to filter data from an external API based on selected categories. We'll be using Xano, a no-code platform for building backend services, and Webflow, a visual development tool for creating websites.
Prerequisites
Before we begin, make sure you have the following:
- A Xano account (you can sign up for free at https://xano.io)
- A Webflow account (you can sign up for free at https://webflow.com)
- Basic understanding of HTML, CSS, and JavaScript
Step 1: Set up Webflow
- Create a new project in Webflow or open an existing one.
- Add a new page called "Filters" (or any name you prefer).
- On the "Filters" page, create the following elements:
- A list item with an ID of
category-container. This will hold the list of categories. - A list item inside
category-containerwith an ID ofcategory-all. This will be the "All" button to show all categories. - A sample card with an ID of
sample-style. This will define the style for displaying each result item. - A div with an ID of
cards-container. This is where the filtered results will be displayed.
Step 2: Set up Xano
- Log in to your Xano account and create a new project (or use an existing one).
- Create two database tables: "Restaurants" and "Categories".
- Add some sample data to the "Restaurants" table, including fields like "name", "description", and "banner_url" (for the restaurant image). Assign categories to each restaurant from the "Categories" table.
- Create two API endpoints: "getRestaurants" and "getCategories".
- The "getRestaurants" endpoint should return a list of restaurants, with an optional input parameter to filter by category IDs.
- The "getCategories" endpoint should return a list of available categories.
Step 3: Write the JavaScript code
- In Webflow, go to the "Filters" page settings and locate the
<script>tags at the bottom of the page. - Copy and paste the provided JavaScript code between the
<script>tags. - Update the
XanoURLvariable with your Xano project's base URL.
This JavaScript code includes the following functions:
getRestaurants(): Fetches the list of restaurants from the Xano API based on the selected category IDs.getCategories(): Fetches the list of categories from the Xano API and creates clickable pills for filtering.resetCategoryFilters(): Resets the category filters and displays all restaurants.pageLoad(): Executed when the page loads, resetting the filters, fetching categories, and fetching all restaurants.
Step 4: Test and customize
- Preview your Webflow project to see the faceted search in action.
- Customize the styling and layout of the category filters and result cards as needed.
- Optionally, enhance the functionality by adding features like search, sorting, or pagination.
By following this guide, you've successfully implemented a faceted search feature that allows users to filter data from an external API based on selected categories. This integration between Xano and Webflow demonstrates the power of no-code tools in building complex applications quickly and efficiently.
Sign up for Xano.
100,000+ people build on Xano.
Start today and scale to millions.