CMS: About Displaying Content from Multiple Collections Using Reference Fields

4 min read
Before you read this article, you might want to read the following:
Reference fields are used to connect one database collection to another database collection. Reference fields also provide you with additional options for displaying your data to your users. 
  • Format a single table, gallery, or repeater to display information from more than one collection.
  • Create a master-detail page to display items from one collection that relate to another collection. 
  • Connect a dropdown list to a reference field so users can save information to your collection.
Note:
You can use galleries, tables, and repeaters when displaying information using reference fields.
The examples in this article use the following collections, where the "Artist" field in the Songs collection is a reference field that connects to the "Name" field in the Artists collection.

Displaying Information from More Than One Collection

Our goal in this scenario is to create one table on our site that lists all the items in our Songs collection based on genre together with the name and photo of their artist, as in the figure below. Remember that this information is stored in two separate but connected collections.
The figure below shows how we set up our table. 
  • The table is connected to the Songs dataset. 
  • The Song column connects to the "Song Title" field in the Songs collection. 
  • The Artist and Photo columns connect to the "Artist" and "Photo" fields in the Artists collection. 
Note how in the Connect Table panel, the Artist and Photo columns show both the name of the referenced collection (Artists), the name of the field ("Name" and "Photo"), and its type (text, image).

When you are selecting a field to connect to an element, the Reference field itself appears grayed-out. It displays the name of the collection it references. The fields in the referenced collection appear indented.

Displaying Filtered Information (Master-Detail)

Our goal in this scenario is to create an artist page that shows information about a given artist from our Artists collection with a list of all their songs from our Songs collection, as in the figure below.



In this case, we need to have two datasets on our page, a primary dataset and a referenced dataset.

The primary dataset connects to the Artists collection. This dataset determines which artist item is currently displayed on the page. In our example above, it is Elvis Presley. If you are doing this on a dynamic page, then your primary dataset is the dynamic dataset for that page.

The referenced dataset connects to the Songs collection. It is filtered by the Artists dataset, so that it can retrieve the items from the Songs collection that match the current artist being displayed on the page.



The figure below shows how the page is set up. The text element and image element on the left are connected to the primary Artists dataset so they can display the name and photo of the artist. The table on the right is connected to the referenced Songs dataset that is filtered by artist, so it can show all the songs from that artist.
Important:
Reference fields cannot be used to build URLs for dynamic pages.

Connecting Dropdown Elements to Reference Fields

You can connect a dropdown list element to a reference field. This means that the items in the dropdown list automatically come from the Main field in the referenced collection. If you do this on an input form, the value selected by your visitor gets saved to the reference field in your collection. 

Did this help?

|