WHAT YOU'LL LEARN
  • what is a reference field
  • how to use reference field

The reference field enables users to link one content model to another. For instance, consider two content models, Product and Category. A product may belong to multiple categories. In such a scenario, we create a reference field in the Product content model that refers to the Category model.

In this tutorial, we will learn how to use reference field. As an example, we will use the Product content model that we created in the Create Content Model tutorial. We will create another content model Category, and give the reference of Category in Product. We will do this in four steps:

  • Step 1: Create a Category content model.
  • Step 2: Add content entries to the Category content model.
  • Step 3: Update the Product content model and add a category reference field to it.
  • Step 4: Create a content entry in the Product content model with reference to the Category content model.

Step 1: Create 'Category' Content Model
anchor

We will create a category content model with the following attributes and fields.

If you are not familiar with how to create a content model, please follow the Create Content Model tutorial.

  1. Create a content model with the following attributes:

    FieldValue
    NameCategory
    Singular API NameCategory
    Plural API NameCategories
    Content model groupIf you have created E-commerce group, select it, else select Ungrouped
    Icon(boxes)
    DescriptionDemo Category content model
  2. Add the following field to the Category content model:

    FieldField Type
    NameText

Step 2: Create 'Category' Content Entries
anchor

  1. From the Side Menu, Click Content Modeling > Models.

    ✔️ The Content Models screen opens.

    1. Hover over the Category content model.
    2. Click View entries.
  2. Click + New Category.

    ✔️ The New Category entry screen opens.

  3. In the Name textbox, type Clothes.

  4. Click Save & Publish.

    ✔️ The Publish Product confirmation screen appears.

  5. Click Yes, publish!

    ✔️ The message “Clothes was published successfully!” displays.

Optional: Similarly, you can create another Category content entry with name Accessories.

Step 3: Update 'Product' Content Model
anchor

  1. From the Side Menu, Click Content Modeling > Models.

    ✔️ The Content Models screen opens.

  2. Hover over the Product content model.

  3. Click ✏️ Edit.

    ✔️ Screen to configure the Product content model’s fields opens.

  4. Drag and drop the Reference field in the Edit tab.

    ✔️ Field Settings - Reference screen opens.

  5. In the Label textbox, type Category.

  6. In the Content Models dropdown, click Category.

  7. Click the Use as a list of references button.

    Note: Since a product can belong to multiple categories, enabling Use as a list of references will allow you to associate multiple categories to a product.

  8. Click Save Field.

    ✔️ Screen to configure the Product content model’s fields opens.

  9. Click Save.

    ✔️ The message “Your content model was saved successfully!” displays.

Step 4: Create 'Product' Content Entry With a Reference to 'Category'
anchor

  1. From the Side Menu, Click Content Modeling > Models.

    ✔️ The Content Models screen opens.

    1. Hover over the Product content model.
    2. Click View entries.
  2. Click + New Product.

    ✔️ The New Product entry screen opens.

  3. In the Name textbox, type Men’s Tiro ‘21 Pants.

  4. In the Description textbox, type Men’s tapered track pants for versatile wear.

  5. In the Price textbox, type 28.

  6. In the Category field:

    1. Click Select an existing record.

      ✔️ The Select an existing record screen opens.

    2. In the search bar, type Clothes.

    3. Click the Clothes list item.

    4. Click Save.

  7. Click Save & Publish.

    ✔️ The Publish Product confirmation screen appears.

  8. Click Yes, publish!

    ✔️ The message “Men’s Trio ‘21 Pants was published successfully!” displays.