Wix Content Collection Fields: Helpful Tips on How to Use Them Properly

Written by velo | Published 2021/03/31
Tech Story Tags: software-development | velo | web-development | wix | beginners | velo-api | tutorial | coding-with-velo

TLDRvia the TL;DR App

Your content collections store your site's content. The collections organize your content with items (rows) and fields (columns). The fields usually describe the items. For example, if one item is a car, a field may list its color. 
The image below shows a collection of 4 fields and 5 items.

Regular Fields

Each field in a collection has a Field Name, Field Key (Velo by Wix only), and Field Type.
Field Name
The Field Name is the label you see at the top of the column in the Content Manager. The Field Name is also used in the connect panel for elements you can connect to a dataset connector in the Editor.
For example, when connecting a text element to a field from your collection, you use the Field Name in the Connect Text panel.
When you add a new field in the Content Manager, you specify the Field Name. You can change the Field Name after the field has been created, and all connections to that field will be updated. 
(Velo by Wix users only) Field Key
The Field Key is used when referring to the field in code using the Data API or Dataset API.
For example, if you want to insert an item using the Data API, you use the Field Key.
wixData.insert("CollectionName", {"fieldKey": "value"});
When you add a new field in the Content Manager, the Field Key is created automatically based on the Field Name. You can specify your own field key, if you wish.
Note:
You cannot change the Field Key once the field has been created.
Field Type
The Field Type defines what kind of content the field contains. When you add a new field in the Content Manager, you choose one of the following Field Types. You can read about field type support and limitations here.
  • Reference
  • Text
  • Image
  • Boolean
  • Number
  • Date and Time
  • Address
  • Rich Text
  • URL
  • File
  • Video
  • Media Gallery
  • Time
  • Tags
The field type is used when connecting page elements to fields in your collections. You can only connect certain input elements to fields of relevant Field Types. For example, you can connect a text element to a Text or URL field but not to an Image field.
While the Content Manager doesn't allow you to add new values of the wrong field type, content imported from a CSV file or added via code is not
validated. For example, you could import a text value to a number field. In this case, the Content Manager will show an error.
You use the Reference field type to select items from the Main field of the referenced collection. For more information, see Adding a Reference Field to a Database Collection.
Note:
You can change a field's type. Make sure to consider the effect this can have on your site before you do so.

Main Fields

Every content collection has a Main field which are used by reference fields
to create connections between collections. A collection's Main field is
indicated by a lock icon next to its field name. By default, the Title field is the Main field. You can define any text field in your collection to be the Main field except for the ID system field.
When you fill in information in a Reference field, you select from the values in the Main field of the referenced collection. If you change the Main field in the referenced collection, the values displayed in the reference field change to match the ones in the new Main field. It is good practice to ensure that each item has a unique value in the Main field.
For more information, see About Reference Fields.

System Fields

Every content collection contains the default fields shown here. They cannot be edited and are hidden by default.

Calculated Fields

When you create a dynamic page, a new field is added to the collection that the dynamic page pulls content from. This field contains a calculated URL with the dynamic page's prefix and the values of the fields that determine which content will be bound to the page.
For example, you might have a dynamic item page to show items from a Dishes collection based on their Title field. In your collection there will be a field called Dishes (Title) with URLs such as /Dishes/pizza and /Dishes/chicken.
When a visitor goes to a dynamic page, all the items in the collection with a URL that matches the URL of the page will be bound to the page's dataset.
For dynamic item pages, each item will have a unique URL. For dynamic category pages, multiple items will share a URL.
You cannot edit the contents of calculated fields. However, if you change
the URL of your dynamic page, the URL in your collection will change
accordingly. If you create multiple dynamic pages based on a collection, the collection will have one calculated field for each dynamic page.
For more information, see About Calculated Fields.

Written by velo | Velo is a full-stack development platform that empowers you to rapidly build, manage and deploy professional web apps.
Published by HackerNoon on 2021/03/31