• Are you a partner? Please find our certification tracks on our legacy Academy.

Reference Field

The Reference field allows you to create references to entries of the same or another content type(s). It lets you access and use entries of other content types as input within your field.

CSendUserTraining_L16_img-1.png

Understanding with an example

Let's understand this using the below diagram:

CSendUserTraining_L16_img-2.png

Consider a 'Blog page,' for example. There can be multiple blogs, each with the same or different authors. In such use cases, we will create two content types to avoid repeatability and create reusable components. The first content type will be 'Blog Page,' which consists of fields such as 'Title,' 'Description,' 'Image,' 'Author,' and 'Published Date.' The second content type will be 'Authors,' consisting of fields such as 'Title,' 'Description,' and 'Image.'

Now you can add the 'Author' content type as a reference field in the 'Blog Page' content type. When you create an entry for the 'Blog Page' content type, you will refer to one of the entries from the 'Author' content type for the 'Author' field. When the page is rendered using Contentstack APIs, the final Blog Page will contain all the content, including the Author details.

Referencing can be classified into ' Self Referencing' and 'Include Referencing.' We can further classify 'Include Referencing' into two more sub-types: ' Single Content Type Referencing' and 'Multiple Content Type Referencing.'

Let's have a look at each of these with examples:

  • Self-Referencing - This refers to creating references of the same content type.
    Example: If a user buys a mobile phone belonging to XYZ brand, they should get recommendations of headsets, chargers, or mobile phone covers of the same brand. In this case, you can create a 'Product' content type with a field named 'Recommendations' as a reference to the same content type 'Product.'

  • Include Referencing - This refers to creating references of another content type(s).

  1. Single Content Type Referencing - Here, the Reference field allows you to create references to entries of a single content type.
    Example: The Blog page and Author example you have seen above best suit this. The 'Author' field in the 'Blog Page' content type references the 'Author' content type. When you create an entry for the 'Blog Page' content type, you will refer to one of the entries from the 'Author' content type for the 'Author' field.

  2. Multiple Content Type Referencing - Here, the Reference field allows you to create references to entries of various content types.
    Example: For an e-commerce site, you may have primary items like Clothes, Shoes, and Bags, and you want to create a page that displays all the products of a selected brand. First, you would create content types like 'Clothes,' 'Shoes,' and 'Bags' and their entries. Then, you would make the 'Brand' content type with the necessary fields and add a 'Reference' field named 'Products' that refers to the three content types 'Clothes,' 'Shoes,' and 'Bags.' When you create an entry for the 'Products,' you can select the entries from the three referenced content types.

The Reference field possesses specific properties you can change anytime per your requirements.

The properties that can be modified are:

  • Basic

    • Display Name

    • Unique ID

    • Instruction Value

    • Help Text

    • Referenced Content Type

CSendUserTraining_L16_img-3.png

  • Advanced

    • Options

      • Mandatory

      • Multiple

      • Non-localizable

CSendUserTraining_L16_img-4.png

Potential Use Case:
  • A reference field can be used to add links between two entries. In the Blog Entries page, the Author can be a reference entry with a separate Author Page, and it's easy to update Author details in one place in the Author content type entry due to referencing instead of each blog article of that Author.

  • Categories are another use case of reference where we can create a separate content type and add them as a reference in articles.

  • In the Navigation Menu, instead of a static link, we can add entry pages as reference menu items for each menu.

Quick Tips:
It's advised to limit content reference depth levels to 3 for better visibility and governance of content.
Also, the maximum number of content types should be limited to 20 in a reference field.

Further Reading