I happen to know many of the readers of CSS-Tricks are strong web designers and developers. Most of you probably don’t use website builders very often, as you are a website builder. You love the control. You love the possibilities. You want to be close to the metal because that’s your expertise.

But you also know the costs. Everything you chose to yourself piles on to the responsibility you take on. Technical debt. Using a site builder like Wix can dramatically reduce that technical debt, and you might be surprised at how little control you have to give up. The following post is about some new and very powerful new features of Wix right up that alley.


One of the cool features of Wix Code is the ability to separate your site’s design and layout from its content. This means you can create and maintain your information in a database and then have your pages dynamically retrieve and display this information in whatever way you like.

Let’s take an in-depth look at what you can do with the Wix Code database, including the types of information you can store, ways you can manipulate data with code, and how you can dynamically display the information on your site.

Throughout this article, we’ll use a simplified example of an art school that stores and displays information about its courses and teachers.

The Wix Code Database

Like all databases, the Wix Code database is made up of individual tables, which we call collections. In our example of the art school (see image below), we have two collections, one each for the courses and teachers.

You can create as many collections as you need and populate them with a near unending amount of data. A robust permissions model means you have complete control over who can access your information and what they can do with it.

You can work directly with your Live data, which is the information your visitors see when they view your pages. You can also work with Sandbox data, so you can try stuff out without affecting your live site. You can sync with them at any time.

Populating Collections

You have several options for populating your collections. You can manually enter data directly in the Wix Content Manager, either to your Live data or your Sandbox data.

If you’re an Excel ace, you can do all the work in Excel (or whatever spreadsheet program you prefer), save your sheet as a CSV file, and then import it into the Wix Code database. In fact, you can create your entire collection this way, schema and all. You can import to your Live data or your Sandbox data.

You can also export your Wix data to CSV files. If you make sure to include the built-in ID system field, you will be able to modify your content in your spreadsheet and then re-import it into your Wix Code database so that each record, or what we call item, is updated.

A third option is to build a form to capture user input and store it in your database.

Using External Databases

If you already have a database somewhere, you might be thinking that you don’t want to recreate it in Wix. The good news is that you don’t have to. As long as your database exposes an API, you can access it from your Wix site.

For simple applications, you can use the wix-fetch module—an implementation of the standard JavaScript Fetch API—to access your external database with an HTTP request and use that data in your Wix site’s pages.

You can also pair the wix-fetch module with another Wix module, wix-router, that lets you control the routing of incoming requests. Using the functionality provided by both of these modules, you can create SEO-friendly dynamic pages that show different data depending on the URLs used to reach them.

For example, you can design a single member profile page that can be used by all of your site’s members.

Using wix-router and wix-fetch you can write code that pulls information from incoming requests for the profile page, queries an external database to retrieve the information for the page, and then injects that data into the profile page. You can even add security to your page by using the wix-users module.

So if you create another page for users to update their profile pages, you can check who is trying to access it and only allow users to update their own profiles.

Data Hooks

You can add hooks to actions on your collections using the wix-data API.

For example, in our Teachers collection, we have two separate fields: First name and Last name. To make displaying names on our pages easier, we also want to have one field that has both names together. To do this, we can add a beforeInsert hook to our Teachers collection that hooks into the insert action, reads the contents of the First name and Last name fields, and then concatenates them and populates the Full name field.

Modeling Your Data

Now that we’ve covered the database itself, let’s talk about modeling your data in the Wix Code database.

Collection Schemas
Like all databases, each collection has a schema to define its fields. All standard field types are supported, including text, image, boolean, number, date and time, and rich text.

There is also a field type specifically designed for URLs. It automatically formats the URL into clickable links that you can add to your pages. For example, teachers in your school could supply the URL of their portfolio website, and you could include that link on their dynamic page.

You can also use the document field type to store a wide range of file types. You can allow your users to download files stored in your collections (such as reading lists for each course) or to upload their own files.

ID Fields and Primary Fields

Each collection has an _ID field, which is the primary key for that table. Collections also have a primary field (indicated by a lock icon), which is the display key for each item.

When you create joins using reference fields (see the next section), the values come from the primary field. The reference itself uses the _ID field, of course. If you plan on using reference fields, it’s a good idea to make sure the data you store in the primary field is unique.

Reference Fields

Reference fields create a connection between collections that is defined in the collection schema itself. This is similar to foreign keys in relational databases.

Each reference field points to a specific collection. The value that is displayed in the reference field in each item in the collection is taken from the value of the primary field of the referenced collection.

In our example, we created a reference field in our Courses collection that points to our Teachers collection so that we can indicate who teaches each class.

The advantage of reference fields is three-fold. First, they help maintain data integrity because their value is taken directly from the referenced collection. Second, they help eliminate data duplication, which we all know is the enemy of good database design. And third, when we create our page layouts, reference fields let us access information in the referenced collection as well as in the main collection we are using. This allows us to create master-detail pages, such as a list of all the courses taught by each teacher.

Creating Pages from Your Content

Of course, storing and maintaining data is nice, but the real point of having a website is displaying content to visitors. So let’s talk about how that works with Wix Code.

Back to our art school example. We have two different types of information: courses and teachers. So you could start by designing a page layout to display all the information about each of the courses. Then you might want to create a master-detail page that lists all of your teachers and the courses they teach.

Setting Up the Dynamic Page

When you create dynamic pages in Wix Code, you first define the URL that will control what content your page can display. Some URLs can specify a single item and others can specify an entire category of items (such as all courses of a certain level).

You set up the URL pattern by picking a field (or fields) from your collection. One URL pattern you could use to display each of your courses could be https://…/Courses/. Each time a different page is generated, the field is replaced by the actual title of the item being retrieved. So one-course page’s URL would be https://…/Courses/Art-History, and another course page’s URL would be https://…/Courses/Intro-to-Painting.</p> <p>Then you design your page layout in the Editor, putting different elements on the page and connecting the ones you want to use to display dynamic data to fields in your collection. You can use text elements, images, buttons, strips, and a variety of multi-item elements like repeaters, tables, and galleries. If you want some items to remain static, such as titles, just don’t connect them.</p> <p>The image below is an example of what a dynamic page layout for our Courses page could look like in the Editor. The square brackets indicate that this content is dynamic. </p> <figure><img src="https://berteau.pro/wp-content/uploads/2018/01/course_y1nwya-1.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_1000,f_auto,https://berteau.pro/wp-content/uploads/2018/01/course_y1nwya-1.png 1000w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_840,f_auto,https://berteau.pro/wp-content/uploads/2018/01/course_y1nwya-1.png 840w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_572,f_auto,https://berteau.pro/wp-content/uploads/2018/01/course_y1nwya-1.png 572w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,https://berteau.pro/wp-content/uploads/2018/01/course_y1nwya-1.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) (min-width: 1251px) calc( (100vw - 530px) / 2 ) (min-width: 1086px) calc(100vw - 480px) (min-width: 626px) calc(100vw - 335px) calc(100vw - 30px)" alt=""></figure> <p>The actual dynamic pages could look something like these.</p> <figure><img src="https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_687,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 687w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_648,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 648w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_617,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 617w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_585,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 585w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_553,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 553w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_522,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 522w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_488,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 488w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_445,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 445w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_405,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 405w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_364,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 364w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_314,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 314w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_261,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 261w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image10_mgrdje-1.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) (min-width: 1251px) calc( (100vw - 530px) / 2 ) (min-width: 1086px) calc(100vw - 480px) (min-width: 626px) calc(100vw - 335px) calc(100vw - 30px)" alt=""></figure> <p>Note how both pages have the same layout. However, some of the elements’ contents have been replaced with the information about the courses from our database. The page background is also different for each page. The container box even enlarged automatically to include the larger course description for the Art History course.</p> <p>Note especially how the name and picture of each course’s teacher appear on the page, even though the details about each instructor are stored in a separate collection from the data about the course. This is because we connected the Courses and the Teachers collections using a reference field, which gave us access to information about the specific teacher for each course.</p> <p>Finally, note how the page URLs are unique to each page. In essence, each of these pages is unique. And Wix Code creates them automatically for us. If we add a new course to our collection, a page for it is automatically created.</p> <h4>Master-Detail Pages</h4> <p>Another cool thing you can do with Wix Code is to create master-detail pages. For example, you could create a page to act as an index that lists all the teachers in your school and the courses each one teaches. This would require pulling information from more than one collection (Courses and Teachers) and then filtering the courses by their teacher so that only the relevant courses are displayed.</p> <p>Our database collections are set up in a many-to-one structure; each teacher has many courses they teach. Whereas above we displayed each course and their individual teacher, now we are taking the opposite approach and displaying each teacher and all their courses.</p> <p>Below is a sample of what an index page with master-detail information might look like using a repeater.</p> <figure><img src="https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png" srcset="https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_452,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 452w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_440,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 440w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_421,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 421w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_394,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 394w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_371,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 371w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_344,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 344w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_319,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 319w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_292,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 292w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_263,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 263w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_233,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 233w, https://res.cloudinary.com/css-tricks/image/upload/c_scale,w_200,f_auto,https://berteau.pro/wp-content/uploads/2018/01/image6_csdhjp-1.png 200w" sizes="(min-width: 1850px) calc( (100vw - 555px) / 3 ) (min-width: 1251px) calc( (100vw - 530px) / 2 ) (min-width: 1086px) calc(100vw - 480px) (min-width: 626px) calc(100vw - 335px) calc(100vw - 30px)" width="350" alt=""></figure> <p>Because the repeater is connected to both our Teachers collection and our Courses collection, it can display the information from both collections dynamically. The embedded table element in each repeater item displays the list of courses each teacher teaches.</p> <h3>Summary</h3> <p>We’ve presented some high-level information about <a href="http://synd.co/2DfBsM3">the Wix Code database</a> and some of the capabilities it offers for storing your data, manipulating your data, and displaying your data dynamically to your visitors. We’ve also illustrated how the options available to you are controlled in part by the decisions you make when you create your collections and connect them. Before you get started creating your Wix Code database, it’s a good idea to spend some time thinking about what kind of information you have and how you want to display it so that you can most effectively model your data.</p> <p><img src=""></p> <hr> <p><small><a rel="nofollow" href="https://css-tricks.com/wix-code-database-data-modeling/">The Wix Code Database and Data Modeling</a> is a post from <a rel="nofollow" href="https://css-tricks.com/">CSS-Tricks</a></small></p> </div><!-- .entry-content --> <footer class="entry-footer"> <span class="cat-links"><i class="fa fa-folder"></i><a href="https://berteau.pro/web-design/" rel="category tag">Blog du designer en herbe</a></span><span class="tags-links"><i class="fa fa-tags"></i><a href="https://berteau.pro/tag/css/" rel="tag">css</a>, <a href="https://berteau.pro/tag/css-tricks/" rel="tag">css-tricks</a>, <a href="https://berteau.pro/tag/dev/" rel="tag">dev</a>, <a href="https://berteau.pro/tag/w3c/" rel="tag">w3c</a>, <a href="https://berteau.pro/tag/webdesign/" rel="tag">webdesign</a></span> </footer><!-- .entry-footer --> </article><!-- #post-## --> <ul class="share-buttons">Partager sur <li><a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fberteau.pro&t=" target="_blank" title="Facebook" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(document.URL) + '&t=' + encodeURIComponent(document.URL)); return false;"><i class="fa fa-facebook-square fa-2x" aria-hidden="true"></i><span class="sr-only">Facebook</span></a></li> <li><a href="https://twitter.com/intent/tweet?source=https%3A%2F%2Fberteau.pro&text=:%20https%3A%2F%2Fberteau.pro&via=originalDonut" target="_blank" title="Tweet" onclick="window.open('https://twitter.com/intent/tweet?text=' + encodeURIComponent(document.title) + ':%20' + encodeURIComponent(document.URL)); return false;"><i class="fa fa-twitter-square fa-2x" aria-hidden="true"></i><span class="sr-only">Tweet</span></a></li> <li><a href="https://plus.google.com/share?url=https%3A%2F%2Fberteau.pro" target="_blank" title="Google+" onclick="window.open('https://plus.google.com/share?url=' + encodeURIComponent(document.URL)); return false;"><i class="fa fa-google-plus-square fa-2x" aria-hidden="true"></i><span class="sr-only">Google+</span></a></li> <li><a href="http://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fberteau.pro&title=&summary=&source=https%3A%2F%2Fberteau.pro" target="_blank" title="LinkedIn" onclick="window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + encodeURIComponent(document.URL) + '&title=' + encodeURIComponent(document.title)); return false;"><i class="fa fa-linkedin-square fa-2x" aria-hidden="true"></i><span class="sr-only">LinkedIn</span></a></li> </ul> </main><!-- #main --> </div><!-- #primary --> <div id="secondary" class="widget-area"> <aside id="calendar-2" class="widget widget_calendar"><h4 class="widget-title">Historique des articles</h4><div id="calendar_wrap" class="calendar_wrap"><table id="wp-calendar"> <caption>août 2018</caption> <thead> <tr> <th scope="col" title="lundi">L</th> <th scope="col" title="mardi">M</th> <th scope="col" title="mercredi">M</th> <th scope="col" title="jeudi">J</th> <th scope="col" title="vendredi">V</th> <th scope="col" title="samedi">S</th> <th scope="col" title="dimanche">D</th> </tr> </thead> <tfoot> <tr> <td colspan="3" id="prev"><a href="https://berteau.pro/2018/02/">« Fév</a></td> <td class="pad"> </td> <td colspan="3" id="next" class="pad"> </td> </tr> </tfoot> <tbody> <tr> <td colspan="2" class="pad"> </td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td> </tr> <tr> <td>6</td><td>7</td><td>8</td><td>9</td><td>10</td><td>11</td><td>12</td> </tr> <tr> <td>13</td><td>14</td><td>15</td><td id="today">16</td><td>17</td><td>18</td><td>19</td> </tr> <tr> <td>20</td><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td> </tr> <tr> <td>27</td><td>28</td><td>29</td><td>30</td><td>31</td> <td class="pad" colspan="2"> </td> </tr> </tbody> </table></div></aside> </div><!-- #secondary --> </div> </div><!-- #content --> <footer id="colophon" class="site-footer"> <div id="middle-footer"> <div class="container"> <aside id="recent-posts-3" class="widget widget_recent_entries"> <h5 class="widget-title">Derniers posts sur le Web Design</h5> <ul> <li> <a href="https://berteau.pro/creating-a-vue-js-serverless-checkout-form-configure-the-checkout-component/">Creating a Vue.js Serverless Checkout Form: Configure the Checkout Component</a> <span class="post-date">12 février 2018</span> </li> <li> <a href="https://berteau.pro/the-wix-code-database-and-data-modeling-2/">The Wix Code Database and Data Modeling</a> <span class="post-date">12 février 2018</span> </li> <li> <a href="https://berteau.pro/how-to-style-a-form-with-tailwind-css/">How to Style a Form With Tailwind CSS</a> <span class="post-date">12 février 2018</span> </li> <li> <a href="https://berteau.pro/creating-vue-js-component-instances-programmatically/">Creating Vue.js Component Instances Programmatically</a> <span class="post-date">12 février 2018</span> </li> <li> <a href="https://berteau.pro/using-css-clip-path-to-create-interactive-effects/">Using CSS Clip Path to Create Interactive Effects</a> <span class="post-date">12 février 2018</span> </li> <li> <a href="https://berteau.pro/2017-2018-javascript/">2017/2018 JavaScript</a> <span class="post-date">12 février 2018</span> </li> </ul> </aside><aside id="text-5" class="widget widget_text"><h5 class="widget-title">sur Google+</h5> <div class="textwidget"><!-- Placez cette balise où vous souhaitez faire apparaître le gadget widget. --> <div class="g-page" data-width="281" data-href="//plus.google.com/u/0/114132426700431473337" data-theme="dark" data-rel="publisher"></div> <!-- Placez cette ballise après la dernière balise widget. --> <script type="text/javascript"> window.___gcfg = {lang: 'fr'}; (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); </script></div> </aside> </div> </div> <div id="bottom-footer"> <div class="container clearfix"> <div class="site-info"> Thème: <a id="theme_lien" href="https://berteau.pro/cvitae/" rel="follow">JCB Web Design</a> créé par Jean-Christophe Berteau </div> <div id="footer-menu" class="menu-footermenu-container"><ul id="footer-menu" class="marioplanet-footer-nav"><li><a title="mentions-legales" rel="me" href="https://berteau.pro/mentions-legales/">Mentions Légales</a></li> <li><a href="https://berteau.pro/a-propos-des-cookies/">A propos des Cookies</a></li> </ul></div> </div> </div> <div id="meta-keywords"> <ul class="keywords"> <a href="https://berteaupao.cluster017.ovh.net/sitesJC/Portfolio/sitesJC/SuperMarioWeb" title="Exemple de création avec SVG et CSS"><li>Création graphique</li></a> <li><a href="https://berteau.pro/web-design" title="Une mine d'informations en provenance de blogs de référence comme CSS-tricks">Web Design</a></li> <li>Charte graphique</li> <li><a href="https://annuaire.laposte.fr/designer/jcb-webdesign-82792123000013/">Internet et digital</a></li> </ul> <ul class="keywords"> <li>Identité visuelle</li> <li>création de logo</li> <li>Présence numérique</li> <a href="https://dev.berteau.pro/sitesJC/NewsLetter/" rel="follow" title="exemple de newsletter repsonsive"><li>Communication professionnelle</li></a> </ul> <ul class="keywords"> <a href="https://ovh.com/" rel="follow" title="Notre partenaire hébergement et nom de domaine"><li>hébergement</li></a> <a href="https://dev.berteau.pro/sitesJC/Boutique/" rel="follow" title="Exemple de boutique en ligne factice"><li>e-commerce</li></a> <a href="https://dev.berteau.pro/" rel="follow" title="vitrine de projets web responsive en cours" alt="https://berteau.pro/projets-web/"><li>site vitrine</li></a> <li>Publicité</li> </ul> </div> </footer><!-- #colophon --> </div><!-- #page --> <script type='text/javascript'> /* <![CDATA[ */ var wpcf7 = {"apiSettings":{"root":"https:\/\/berteau.pro\/wp-json\/contact-form-7\/v1","namespace":"contact-form-7\/v1"},"recaptcha":{"messages":{"empty":"Merci de confirmer que vous n\u2019\u00eates pas un robot."}}}; /* ]]> */ </script> <script type='text/javascript' src='https://berteau.pro/wp-content/plugins/contact-form-7/includes/js/scripts.js'></script> <script type='text/javascript'> /* <![CDATA[ */ var countVars = {"disqusShortname":"jcb-web-design"}; /* ]]> */ </script> <script type='text/javascript' src='https://berteau.pro/wp-content/plugins/disqus-comment-system/public/js/comment_count.js'></script> <script type='text/javascript' src='https://berteau.pro/wp-content/themes/MarioSVGplanet/js/modernizr.js'></script> <script type='text/javascript' src='https://berteau.pro/wp-content/themes/MarioSVGplanet/js/jquery.bxslider.js'></script> <script type='text/javascript' src='https://berteau.pro/wp-content/themes/MarioSVGplanet/js/jquery.superfish.js'></script> <script type='text/javascript' src='https://berteau.pro/wp-content/themes/MarioSVGplanet/js/marioplanet-custom.js'></script> <script type='text/javascript' src='https://berteau.pro/wp-includes/js/wp-embed.min.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.0/prism.min.js"></script> </body> </html>