Hygraph
Docs

#Lesson 1.2 - Build your content models

In this lesson, you will create the base content models for the e-commerce project. These models are intentionally incomplete at this stage. References, components, and remote fields are added in later lessons.

#Asset model

Before creating models, you need to add two fields to the Asset model. Product images require alt text and captions. Both fields are localized, so translated values can be added when Spanish localization is configured in lesson 6.2.

Asset model - Alt text
  1. In your Hygraph project, click Schema, and then under Models, click Asset.

  2. In the right sidebar, click +Add next to Single line text. Provide the following information, and click Add to save:

    FieldInput
    Display nameAlt text
    API IDaltText
    DescriptionAdd alternative text for the image here
    Localize fieldSelect checkbox
  3. Add a second Single line text field for the caption, and click Add to save:

    FieldInput
    Display nameCaption
    API IDcaption
    DescriptionAdd image caption here
    Localize fieldSelect checkbox

Your Asset model should look like this:

Your Asset modelYour Asset model

#Product

The Product model holds information for product listings.

Add fields to Product model

To create the Product model, follow these steps:

  1. Click +Add next to Models.

  2. Provide the following information, and click Add Model to save:

    FieldInput
    Display nameProduct
    API IDProduct
    Plural API IDProducts
    DescriptionTutorial project Product model
  3. Add the following fields to the Product model:

    Single line text - Product name:

    FieldInput
    Display nameProduct name
    API IDAuto-completed. Leave as is.
    Use as title fieldSelect checkbox
    Localize fieldSelect checkbox
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox

    Slug - Product Slug:

    FieldInput
    Display nameProduct Slug
    API IDAuto-completed. Leave as is.
    LowercaseLeave selected
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox
    Match a specific patternSelect checkbox, then select Slug from the dropdown
    Custom error messageInput value does not match the expected format.

    Asset picker - Product image:

    FieldInput
    Display nameProduct image
    Allow multiple assetsSelect checkbox

    Rich Text - Product description:

    FieldInput
    Display nameProduct description
    API IDAuto-completed. Leave as is.
    Enable embeddingSelect checkbox. Select the Asset and Product models from the dropdown.
    Localize fieldSelect checkbox

    Enabling embedding on the Product description field allows editors to embed images and product entries directly in the description body. The Product category model does not exist yet, so you will add it after creating that model.

    Float - Product price:

    FieldInput
    Display nameProduct price
    API IDAuto-completed. Leave as is.

Your Product model should look like this:

Your Product model so farYour Product model so far

This model is not finished. A product variant component is added in lesson 4 and a reviews remote field in lesson 5.

#Product category

The Product category model holds categories that products are assigned to. It connects to the Product model through a reference, which we configure in lesson 2.

To create the Product category model, follow these steps:

  1. Click +Add next to Models.

  2. Provide the following information, and click Add Model to save:

    FieldInput
    Display NameProduct category
    API IDProductCategory
    Plural API IDProductCategories
    DescriptionSelect a product category
  3. Add the following fields to the Product category model:

    Single line text - Category name:

    FieldInput
    Display nameCategory name
    Use as title fieldSelect checkbox
    Localize fieldSelect checkbox
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox

    Slug - Slug:

    FieldInput
    Display nameSlug
    LowercaseLeave selected
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox
    Match a specific patternSelect checkbox
    Custom error messageInput value does not match the expected format.

    Rich Text - Description:

    FieldInput
    Display nameDescription
    Localize fieldSelect checkbox

Your Product category model should look like this:

Your Product category model so farYour Product category model so far

Now return to the Product model and edit the Product description Rich Text field. Add Product category to the Enable embedding dropdown.

Product category in Rich Text embedsProduct category in Rich Text embeds

Schema building is not always linear. Models are interconnected, and you will sometimes need to return to an earlier model after creating a later one. This is expected.

#Blog post

The Blog post model holds articles that promote products.

To create the Blog Post model, follow these steps:

  1. Click +Add next to Models.

  2. Provide the following information, and click Add Model to save:

    FieldInput
    Display NameBlog Post
    API IDBlogPost
    Plural API IDBlogPosts
    DescriptionArticles to promote our products
  3. Add the following fields to the Blog Post model:

    Single line text - Title:

    FieldInput
    Display nameTitle
    Use as title fieldSelect checkbox
    Localize fieldSelect checkbox
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox

    Slug - Slug:

    FieldInput
    Display nameSlug
    Generate slug from templateSelect checkbox
    Slug template{title}
    LowercaseSelect checkbox
    Match a specific patternSelect checkbox, then select Slug from the dropdown
    Custom error messageInput value does not match the expected format.

    Rich Text - Body:

    FieldInput
    Display nameBody
    Localize fieldSelect checkbox
    Enable embeddingSelect checkbox. Select Blog Post, Product, and Product category from the dropdown.

Your Blog post model should look like this:

Blog post model fieldsBlog post model fields

#Seller information

The Seller information model holds business details referenced from the landing page.

To create the Seller information model, follow these steps:

  1. Click +Add next to Models.

  2. Provide the following information, and click Add Model to save:

    FieldInput
    Display NameSeller information
    API IDSellerInformation
    Plural API IDSellerInformations
  3. Add the following fields to the Seller information model:

    Single line text - Business name:

    FieldInput
    Display nameBusiness name
    Use as title fieldSelect checkbox
    Localize fieldSelect checkbox
    Make field requiredSelect checkbox

    Slug - Slug:

    FieldInput
    Display nameSlug
    LowercaseLeave selected
    Make field requiredSelect checkbox
    Set field as uniqueSelect checkbox
    Match a specific patternSelect checkbox, then select Slug
    Custom error messageInput value does not match the expected format.

    Asset picker - Business logo:

    FieldInput
    Display nameBusiness logo

    Rich Text - Business description:

    FieldInput
    Display nameBusiness description
    API IDAuto-completed. Leave as is.
    Localize fieldSelect checkbox

#Landing page

The Landing page model supports flexible page structures. It is intentionally minimal at this stage. Component fields and references are added in lessons 2 and 4.

  1. Click +Add next to Models.

  2. Provide the following information, and click Add Model to save:

    FieldInput
    Display NameLanding page
    API IDLandingPage
    Plural API IDLandingPages
  3. Add the following fields to the Landing page model:

    Single line text - Landing page title:

    FieldInput
    Display nameLanding page title
    Use as title fieldSelect checkbox
    Localize fieldSelect checkbox

    Slug - Link:

    FieldInput
    Display nameLink
    API IDAuto-completed. Leave as is.
    Generate slug from templateSelect checkbox
    Slug template{landingPageTitle}
    LowercaseLeave selected
    Set field as uniqueSelect checkbox
    Match a specific patternSelect checkbox. Select Custom and enter: ^[a-z0-9\/]+(?:[-\/][a-z0-9]+)*$
    Custom error messageInput value does not match the expected format.

The Navigation model is included in the cloned project. At this stage it contains the Nav ID field, which is a slug field used as the navigation identifier. This model is incomplete. A way to hold navigation links is added in lesson 4.2 after creating the Link component.

#What's next

Lesson 2 - References

Or, go to the Tutorial overview for the full lesson list.