A Studio Two site can work with collection data in two ways. You can connect page elements to a CMS Data Source with Connect to Data in the Studio Two editor, or you can write code that uses the Data API.
Both ways use the same collections, the same data, and the same permissions. They differ in what they can do and in how much code you write. Many sites use both.
Wix creates CMS Data Sources for each collection. When you attach one to a page or section, you can connect elements, such as text, images, and repeaters, to the collection's items and fields. You don't write any code. For how to attach a Data Source, see Connect to Source.
- No code: You set up the connection in the editor.
- Built-in display features: The Data Source handles the current item, paging with a load more option, and the filtering, sorting, and page size that you set on it.
- Dynamic pages: On a dynamic item page, the item page Data Source always holds the current item, so connected elements show that item.
- Fast setup: You can display collection data on a page in minutes.
- Read only: CMS Data Sources display data. They don't add, update, or remove items.
- Frontend only: Binding happens on the page. It can't run backend logic.
- Limited to what the Data Source exposes: You can't add custom queries, aggregations, or logic beyond the settings the Data Source offers.
Use Connect to Data when you need to:
- Display collection items in repeaters, galleries, or other elements.
- Build dynamic pages that display a different item on each URL.
- Use standard filtering, sorting, and paging without custom logic.
- Set up a page that displays data, without writing code.
The Data API gives site code direct access to a site's collections. You write code to query, add, update, and remove items, and your code passes the results to the elements that display them.
The Data API manages collections, indexes, external database connections, and more.
- Full control: You decide exactly how to query and change data, and which logic to run.
- Writes: You can add, update, and remove items.
- Advanced queries: You can use complex filters, aggregations, and field projection.
- Backend code: You can run data operations in backend code, where you can also elevate permissions.
- Bulk operations: You can process many items in one call.
- Code required: You write and maintain code for every data operation.
- Manual display: The Data API doesn't display anything by itself. Your code must pass the results to page elements, for example through a custom Data Source, and keep them up to date when the data changes.
- Longer setup: It takes longer than connecting elements in the editor.
Use the Data API when you need to:
- Save data, such as visitor input from a custom form.
- Run advanced queries, aggregations, or custom search.
- Run data operations in backend code.
- Combine data with other APIs or external systems.
- Process many items at once.
You can combine the two approaches. For example, connect a repeater to a CMS Data Source to display listings, and use the Data API in backend code to save new listings that visitors submit.