Learn how to build a coffee catalog app using Wix Blocks. The app includes a widget that presents the products in a repeater, including a nested repeater for various rating options. It also allows users to configure it through dashboard pages.
To help you get started quickly, we’ve provided a template of the app. Follow the next steps to get your own copy of the template.
Make sure you're logged in to your Wix Studio account. If you don’t already have one, sign up for a Wix Studio account.
Come up with a unique string for your app's namespace. If you do this tutorial more than once under the same Wix account, provide a different string each time.
Copy the following URL to your clipboard (but do not paste it in your browser yet).
Insert your unique string in the designated place, after the term namspace=
. Make sure to delete the brackets.
Go to your browser and paste the link you created. Blocks will open with your own copy of the app.
The app you just created includes the following segments for you to work with:
First, complete the Products widget by adding the Taste Notes widget as a nested widget.
When added, the Taste Notes widget appears in a random location inside the Products widget. Let’s position it properly.
Now, the nested widget is neatly placed within the main widget.
Now is a good time to check the Layers panel to understand the structure of widgets and the repeaters in them:
Let’s create a collection, which will store data for the coffee catalog. The collection includes the following fields:
The Taste Notes field contains an array of title-value pairs representing flavor intensity, for example:
["crisp:3","caramel:2","nutty:2"]
To save time, we’ve created a data file with five sample items for you.
Your new collection is currently empty. Now, let's configure the Coffee Name and Taste Notes fields to ensure the data imports correctly.
Click More Actions > Import Items, then select the file you downloaded.
In the Configure Column dropdown for Coffee Name, select Existing Field.
Verify that Map to Collection Field is now set to Title.
Check the box next to Taste Notes to include it in the import.
In the Configure Column dropdown, select New Field.
Change Field Type to Text, then click Next.
The Created Date, Updated Date, and Owner fields won’t be imported—that’s fine. Click Import to complete the process.
The Taste Notes field was imported as plain text, but it should be an Array containing title-value pairs. Let’s update its type.
Click the three dots next to Taste Notes, then select Edit.
Click Change Type and scroll down to find Array. Select it. Accept the notification - about changing the field type.
After making these changes, your collection should look like this:
You can close the collection now.
collectionUtils.js
fileSince you’re working with a template, update the placeholder collection name in the collectionUtils.js
file.
Open the Your Collections tab.
Click the three dots next to your collection name.
Select Edit Settings.
Copy your Collection ID (e.g., @user/coffee-catalog/Import360
).
Open collectionUtils.js
.
Replace the placeholder text in the return
statement of the getCollection()
function with your Collection ID. For example:
Let's load the data from the collection to the main repeater, productsRepeater
.
Go to the Products widget code panel.
Delete the boilerplate code and paste the following code, to load the repeater with the data from the collection.
You have an error in the notes
property and this is expected. We'll handle it in the following steps.
Now click the icon and preview your widget. Since we didn't connect the Test Notes widget yet, the notes aren't shown yet.
In order to pass data from the Products widget to the nested Taste Notes widget, we'll create a new widget API property in the nested widget. We'll name the property notes
.
The data from this property will be used to update the notesRepeater
and the rating
repeater that's nested in it.
notes
.notes
.Text
.notes
propertyWe’ll now add the code to handle the notes
property in the onPropsChanged()
function of the Taste Notes widget. This code will:
notes
data into a format that the repeater can use.notesRepeater
with the transformed data.rating
repeater by creating a list of rating icons based on the note's value.Delete the boilerplate code in the Taste Notes widget and copy the following instead:
Go to Preview in the Products widget, to see that everything is working.
Now we'll start managing the Dashboard Pages of the app. Dashboard pages are the back-office of your app, enabling users to manage its data. This app includes two dashboard pages, which we have already designed:
Every dashboard page has an ID, which is used in the app code. Let's copy these IDs and paste them in our constants.js
file.
Click the Dashboard Interface icon.
Select the Manage Products dashboard page.
Hover over the three dots and click Page Settings.
Copy the Page ID.
Click the Public & Backend icon {} and open the constants.js
file.
Paste the copied Page ID into the appropriate place, replacing the placeholder text in the constants.js
file.
Repeat the process for the Product Form dashboard page to copy and paste its Page ID.
Let's add the code for the Manage Products page.
Select the Manage Products dashboard page and open its code panel.
First, import the required libraries and constants. These provide access to Wix's dashboard, data manipulation functions, and constants for page navigation and default settings.
In the $w.onReady()
, initializes the page by setting up two actions:
productsRepeater
with the retrieved data.Still in the $w.onReady()
, add the $w('#productsRepeater').onItemReady()
function. This function sets up event handlers for each item in the repeater. The function:
Let's add the handleRemove()
function. This function:
Let's add the code for the Product Form dashboard page. This form displays an empty form for adding a new product, or a form with the product details for editing an existing product.
Select the Product Form dashboard page and go to its code panel.
First, import some necessary modules and define two global variables, productId
and repeaterData
, which will be used later.
$w.onReady()
functionThe onReady()
function initializes the page with the following actions:
observeState
function listens for state changes and determines whether to load an existing product or reset the form.
When the Manage Products page navigates to this form, it either includes a product ID or not.
Add this code as your onReady()
function:
loadProduct()
functionAdd a loadProduct()
function, which populates the form's inputs fields with product data.
Add a setNotesRepeaterData()
function, which formats and assigns taste notes data to the repeater. The function:
Splits each taste note into note and rating.
Ensures at least three note slots are always available.
Updates the repeater with structured data.
Add a resetForm()
function, which clears all form fields and sets a default image.
Add a saveProduct()
function. When the Save button is clicked, the function:
Gathers all input values from the form.
Converts taste notes into a formatted array ("note
").If the product already exists (productId
is set), it updates the record.
If no ID exists, it creates a new product.
Displays a toast notification when the save is successful.
Add a handleImageUpload()
function, which uploads the selected file and updates the product image field. If the upload fails, it resets to the default image and shows an error toast.
Blocks installation settings determine how your app behaves when installed on a site.
Let's remove the Taste Notes widget from the + Add Elements panel of a user's editor, since it’s a nested widget.
Click on the Taste Notes widget name.
Hover over the three dots and select Editor Experience > Edit Installation Settings.
Uncheck the box under Show in Add panel to prevent the widget from appearing in the + Add Elements panel.
Another step we'd like to configure for better usability, is removing the Product Form dashboard page from user's site menu. This form should only be reachable from the Manage Products page. To remove the page from the menu:
Click on the Product Form dashboard page.
Hover over the three dots and click Hide from dashboard menu.
Congratulations! Your app is now ready to be tested in the editor or installed on a site.
If you want to install the app on other sites or manage its versions, go back to Blocks. Click Release to create a major version, then follow the steps to install it on a site.