Easily restore your project to a previous version with our new Instant One-click Backup Recovery
Hygraph
Docs

Reference FAQ component

#Overview

This guide shows how to create an FAQ component to create lists of pre-defined Q&A pairs. This component can be used in any model in your project.

You'll create a model that contains the data for the Q&A pairs and a component that lets you create a list of questions and answers, adding this information through a reference field.

Reference FAQ ComponentReference FAQ Component

This recipe is a great option if you prefer to work on Q&A pairs as individual content pieces that you can easily add to models or components to create the FAQ list. It is also a great option if you need to show different sets of Q&A pairs throughout your website, as it allows you to take the resulting component, and add it to any model in your project.

This mock image shows what a frontend using this setup could look like:

Mock ImageMock Image

#Prerequisites

  • REQUIRED: You need to have a Hygraph account. If you don't have one, you can sign up here.
  • REQUIRED: You need to have a Hygraph project. Look into the following section to learn more about your options.

#What you can do

Use this guide to create a Reference FAQ Component. You have two options:

  • OPTION 1: Create a project. This is the way to go if you want to follow the entire tutorial for learning purposes.
  • OPTION 2: Use an existing project of yours. This is the way to go if you already have a project and want to add this model. In this case, you may need to adjust parts of the tutorial to your own project schema.

#Not in the mood to start building?

Clone the entire cookbook

This is the way to go if you're curious about how we built the FAQ recipes but don't want to follow the step-by-step creation process. This project contains the entire FAQ Cookbook so you can compare recipes or look into what instances they contain.

#Core concepts

In this guide, you'll work with different schema elements to create a Reference FAQ Component. Let's look into them:

  • Model: Your schema is the content structure of your project. You can define your schema by creating models, adding fields, reusable components, and sidebar widgets, integrating remote sources, and establishing relationships with other models.
  • Component: a predefined set of fields that can be reused across models and content entries. You can think of a component as a flexible, reusable template: you define the fields that will be used inside a component once and then fill them with different content every time you use it in a content entry.
  • References: References are relations between two or more content entries in your project. With references, you can reuse content entries by connecting them. Once the relation is configured, you can also create related content directly from the content form.

#Step-by-step guide

This video follows the same step-by-step tutorial offered in this document.

#1. Create the FAQ list model

This model will let you create Q&A pairs as content entries.

To create the model, navigate to the Schema builder and click +Add next to Models. Use the following information:

FieldInput
Display nameFAQ List Single
API IDFaqListSingle
API ID PluralFaqListSingles

Click Add Model to save.

Now that the model has been created, you can start adding fields to it.

We will add a Single line text field to use as question, and a Rich Text field for the answer.

Let's start with the question. Add a Single line text field from the right sidebar, and use the following information:

TabFieldInput
SettingsDisplay nameQuestion
SettingsAPI IDquestion
SettingsDescriptionWrite the question here
SettingsUse as title fieldLeave this checkbox selected
ValidationsMake field requiredSelect this checkbox
ValidationsSet field as uniqueSelect this checkbox

Click Add to save.

Next, you want include a rich text field for the answer, which will also allow some formatting. Add a Rich text field from the right sidebar, using the following information:

TabFieldInput
SettingsDisplay nameAnswer
SettingsAPI IDanswer
SettingsDescriptionWrite the answer here
ValidationsMake field requiredSelect this checkbox

Click Add to save.

We chose to create the FAQ list as a model because in a use case like this, we want to create question & answer sets as content entries that can be easily referenced in other models or components later on. In the next step, we will create the Reference FAQ Component, which will contain a reference field that connects this model. This will allow editors to quickly set up lists of Q&A pairs.

#3. Create the Reference FAQ Component

To create the component, navigate to the Schema builder and click +Add next to Components. Use the following information:

FieldInput
Display nameReference FAQ Component
API IDReferenceFaqComponent
API ID PluralReferenceFaqComponents

Click Add component to save.

This component will contain only two fields: a Single line text field for the FAQ section title, and a Reference field to add lists of Q&A from the model you created in the previous step.

Let's start with the title. Add a Single line text field from the right sidebar, and use the following information:

TabFieldInput
SettingsDisplay nameFAQ Section title
SettingsAPI IDfaqSectionTitle
SettingsDescriptionWrite a section title here
SettingsUse as title fieldLeave this checkbox selected

Click Add to save.

Next, you will create a reference field that will allow editors to add Q&A pairs from the model you created in the previous step.

Add a Reference field from the right sidebar, using the following information:

TabFieldInput
DefineAllow only one model to be referencedSelect this radio button.
DefineModel to referenceuse the dropdown to select FAQ List Single
DefineReference directionUse the radio button to select One-way reference
DefineRelation cardinalityOne to Many
DefineAllow multiple (…)Select this checkbox
ConfigureDisplay nameQ&A Pair
ConfigureAPI IDqAPair
ConfigureDescriptionLink a Q&A pair or create a new one

Click Add to save.

Your component is ready! This is how you build an FAQ component that uses references to link Q&A pairs.

#Resulting content form

If you were to use this component in a model, the component section of the resulting content form should look like this:

Resulting content formResulting content form

Editors will be able to easily link existing Q&A pairs from the FAQ List model.