How to build a frontend for Supabase using Webstudio
In Webstudio, a "Collection" is a powerful feature designed to manage and display dynamic content on web pages. Essentially, they serve as containers that can connect to various data sources, like databases or APIs, to fetch and present data in a structured and repeatable manner. This allows developers and designers to create instances, such as lists, galleries, or testimonial sections, where each item in the collection is automatically populated with data from the connected source. By using a collection, Webstudio users can efficiently create pages with content that updates in real-time, reflecting changes in the data source without manual intervention, thereby enhancing the site's interactivity and relevance.
Dynamic Content Creation with Webstudio and Supabase
To create pages featuring dynamic content in Webstudio by integrating Supabase as your data source.
Setting Up Your Supabase Project
Sign up for a free Supabase account.
Create a new project. (You'll need to set a strong password for your project to proceed).
Once your project is initialized, navigate to the table editor to create a new table
Define your fields (e.g., text fields for name, testimonial content, and an image URL field)
Uploading Images to Supabase Storage
Go to Storage in your Supabase dashboard
Create a new bucket and set it as public
Upload your images
Each image will have a URL you can copy and store in your table
Configuring Row Level Security (RLS)
Navigate to your table β "No active RLS policies"
Create a new policy
Enable read access for everyone (anonymous users)
Save the policy
Integrating Supabase with Webstudio
Getting the API URL
Go to Table Editor β select your table
Click API (at the top right of the table view)
Switch the example code to bash
Copy the URL provided
Adding the Resource Variable
In Webstudio, select your Collection's parent element
Go to Settings β Add Variable β Type: Resource
Paste the API URL
Add a Header:
Name:
apikeyValue: Your public API key from Project Settings β API
The API key stays between you and the builder and is not exposed on the frontend.
Mapping Data and Finalizing Your Page
Map the data from Supabase to your Webstudio project. This involves setting up the data within your collection to inform Webstudio about the available data for use.
Delete any automatically generated preview box within the collection.
Drag in your pre-created and pre-styled components, which will be repeated for each fetched item from Supabase.
For each component (e.g., paragraph, field, and image), bind the corresponding data from your Supabase collection.
Use
.datato access the actual content (e.g.,resource.data)When binding inside a Collection, use
collectionIteminstead of the resource nameOnce everything is connected and data is properly mapped, your page will dynamically display the testimonials stored in Supabase.
Make sure to check the responsiveness and appearance on mobile devices before publishing.
Last updated
Was this helpful?
