This tutorial walks you through building the Recipes app. The app showcases recipes on Wix sites, so site visitors can see an image, description and rating for each recipe. They can also subscribe to get new recipes.
The app includes:
Ready to begin? Create your own copy of the app in Blocks. The link leads to a template with most of the design and some of the code ready.
Notes: Throughout this tutorial, you'll move back and forth from creating the app in Wix Blocks to testing it on a Wix site.
Design Presets are Block's way of allowing you to have multiple design and layouts for the same widget. They are often used for adapting the app for different devices, like desktop and mobile. The first thing we'll do is create another preset for when the widget is used on a mobile phone. This preset will be a duplicate Card Layout preset, with a few changes.
Tip Can't see the size of the widget and the grid as presented in the screenshot below? Use the Layers menu to verify you are selecting the entire widget and not one of its elements.
8. Click the Design tab.
9. Change the title's font site to 18.
10. Click on the Description, click and set it to Don't Display, to hide the description in mobile.
11. Go back to the Card Layout preset and check that the description does appear there.
Build the app, to create an initial version of it, which you can install on a site. You'll build the app several times during this tutorial.
This steps creates a new Wix site and installs the app on it. Note that installing the app is not enough, you also must add the appropriate widget from the Add panel.
Now let's do some actions on this widget in the site, just to see how it works.
4. Right Click on the widget and click Reset Widget, to go back to the original design.
Now, go back to Blocks to continue creating the app.
7. Copy the collection ID
8. Go to collectionUtils.js file in the Public and Backend files. This is the file for interacting with the app's collection.
9. Change the value of collectionName from '@wixBlocks/recipes-app/recipes' to your collection ID.
This step populates the repeater with the data from the collection, using code.
Code snippets You can also find the following code snippets in the codeSnipets.js file in the Public and Backend section.
This is the full widget code at the moment:
In the previous step we defined the repeater to show 4 items from the database. But what if a site builder who installed your app wants to show a different number of items? Let's add a property to the Recipes widget API. The property will hold the number of items to display in the widget, and will replace the constant number of 4 that we added in the previous step.
5. Make the populateRepeater function call send the prop as a parameter instead of the 4.
The onPropsChanged() function is triggered when an event of props changing is detected. You can add custom logic to this function.
6. Await the initRepeater() function in your onPropsChanged() function:
Here is the full widget code, after adding the property.
When a site builder installs your widget, they can change the value of the properties with an autogenerated Settings panel in your widget's floating menu. However, you can also build a custom panel and add custom logic to it.
This is the full panel code:
Tip Note the wix-widget and wix-editor modules at the beginning of the panel code. They are unique to Blocks custom panel code.
The Configuration tab in the Editor Experience panel allows you to control the editor experience of a site builder who installs your app.
Now, whenever a site builder clicks "Settings", they will see your custom panel.
Another change you can do in the Configuration tab, is prevent layout elements from being selected. A site builder has no reason to select the repeater in your widget.
4. Select the repeater and uncheck Element can be selected box.
Let's check that the app works on your site.
Now let's add data to the collection in the site, to check the app functionality. You need to add data because when a Blocks app is installed on a site, the collection structure is copied to the site, but not the data (learn more).
3. Go to the CMS and add the CMS to your site.
4. Find your collection.
5. Click on the collection name and open it. See that the default data from Blocks was imported.
6. Click on your widget's Settings button and change the number of items to display.
7. Go to preview and see that the number of items changed. If it did, your test is complete!
Blocks allows you to create another widget and insert it inside the main widget. For example, let's say that you want to allow people to subscribe to an email list through your Recipes app. To this, we created another widget, named Subscription. However, this is just a dummy widget for the purpose of this tutorial - we didn't implement the code. This is how you add the Subscription widget to your Recipes widget:
4. Drag the Subscribe widget to be on the top part of your Recipes widget.
Let's make some layout changes to adapt the Subscribe widget to the Recipes widget.
5. Right click on the Subscribe widget and select Use on All Presets. Now your layout changes apply to all presets.
Let's make some more changes in the mobile preset.
1. Go back to the Design Presets section of Widgets and Design and click your Mobile Layout preset.
2. In the inspector, change the Width to 86%.
3. Align to center - both vertically and horizontally.
Now we want an easy way for users to interact with the collection of recipes, so they can add and manage their recipes. For this, we have the app's Dashboard (learn more). When a site builder installs your app on a site, the Dashboard page will be added with it.
Note wixDashboard.navigate() gives you the ability to navigate to other dashboard pages. You must enable Dev Mode in your site to do so.
4. Look at the Dashboard's code tab to see the buttons' code:
Note The initRepeater() function in the dashboard code looks almost identical to the initRepeater() in the widget code. They both use the functions from the repeaterUtils.js file.
5. In the Dashboard page, go to Preview and try adding another recipe.
Now that we finished building our app, it's time to build a major version (learn more about versions in Blocks).
7. Click Build and select Major Version.
2. Open the sites' dashboard.
3. You'll see new dashboard page with your app's name. Click on it.
4. Click Add Recipe and add an item in the dashboard.
5. Click Manage Collection. Open the collection and view the item you just added.
6. You can also go back to the site editor and change the number of items again.
Blocks installation settings determine how this app is installed for other people's websites.
6. Click the Recipes widget. Set it to be Added to current page.
7. As a default preset, choose the Editorial Layout.
8. Choose the Mobile Layout preset to be the default for mobile.
9. Click Save.
10. Go back to Blocks and click Build again to apply the installation settings.
11. To see the installation settings in action, you need to uninstall and reinstall the app.
Blocks apps can be used on your own sites and save you lots of copy-and-paste. They can also be published and sold in the Wix App market and earn money. The last thing we'll do is simulate how to publish your app, in case you want to publish your own app in the future.
Now your app has a premium plan. The next step is to configure what happens in Blocks according to the different plans that a user purchased. What extra abilities do you want them to have? For example, in our app, we might want the subscribing option to be disabled until a user paid. Learn more about adapting your app to a pricing plan.