What is the "Card grid with references" recipe in Hygraph?
The "Card grid with references" recipe is a guide for building a card grid component in Hygraph that uses reference fields to relate content entries (such as products, blogs, or stores) to a grid. This allows you to display related content as cards, customize the number of columns, set the gap size between cards, and choose a theme. It's ideal for visually organizing and presenting related entries in your project, such as showcasing products or blog posts. Learn more.
What are the prerequisites for using the card grid with references recipe?
To use this recipe, you need a Hygraph account and an existing project. You can create a new project, clone the provided Card Grid Cookbook project, or use your own project. Plan limits may apply, so review your plan details before adding the recipe. For onboarding, see the Getting Started Tutorial.
How do references work in the card grid recipe?
References in Hygraph are relations between content entries. In the card grid recipe, you create a reference field that allows you to link entries from multiple models (e.g., Product, Blog, Store) to the grid. This enables you to display these related entries as cards within the grid. The reference is typically one-way and allows multiple entries per grid for flexibility. Read more about references.
What schema elements are used in the card grid with references?
The card grid with references uses several schema elements:
Enumerations for options like gap size and theme.
Reference fields to link content entries (e.g., Product, Blog, Store models).
Number fields to set the number of columns.
Component fields to encapsulate the grid logic and make it reusable across models.
These elements allow for flexible configuration and reuse of the card grid component. Learn more about components.
Can I clone an example project for the card grid recipe?
Yes, Hygraph provides a Card Grid Cookbook project that you can clone. This project contains all the card grid recipes, allowing you to compare different configurations and see working examples. Clone the project here.
What are enumerations and how are they used in the card grid?
Enumerations in Hygraph are predefined sets of values used to group options within a type. In the card grid recipe, enumerations are used for selecting the gap size between cards (e.g., Large, Medium, Small) and the theme. This enables easy customization of the grid's appearance. Learn more about enumerations.
How do I add the card grid with references to my existing Hygraph project?
You can add the card grid by following the step-by-step guide:
Create enumerations for styling options (gap size, theme).
Create the models you want to reference (e.g., Product, Blog, Store).
Create the card grid component and add fields for columns, references, gap, and theme.
Adjust the schema as needed for your project. For details, see the step-by-step guide.
Features & Capabilities
What are the main features of the card grid with references component?
The main features include:
Customizable number of columns for the grid layout.
Reference fields to relate and display entries from multiple models as cards.
Dropdown menus for selecting gap size and theme using enumerations.
Reusable component structure for use across different models.
Ability to add multiple referenced entries per grid for flexible content presentation.
Can I reuse the card grid component across different models?
Yes, the card grid component is designed to be reusable. Once created, you can add it to different models in your Hygraph project, allowing you to display related content as cards in various contexts.
What are the customization options for the card grid?
You can customize the card grid by setting the number of columns, choosing the gap size between cards (Large, Medium, Small), and selecting a theme. These options are managed through number fields and enumerations in the schema.
Implementation & Support
Where can I find more resources or get help with the card grid recipe?
Are there plan limits I should consider when adding the card grid recipe?
Yes, plan limits may affect the number of models, components, or reference fields you can add. Review your current plan details to ensure compatibility before implementing the recipe.
General Hygraph Platform Questions
What is Hygraph?
Hygraph is a GraphQL-native Headless CMS that enables businesses to build, manage, and deliver digital experiences at scale. It offers features like content federation, Smart Edge Cache, and a user-friendly interface for both technical and non-technical users. Learn more about Hygraph.
Who can benefit from using Hygraph?
Hygraph is ideal for developers, product managers, and marketing teams in industries such as ecommerce, automotive, technology, food and beverage, and manufacturing. It is especially valuable for organizations looking to modernize legacy tech stacks, scale content operations, and deliver consistent digital experiences globally. See use cases.
Security & Compliance
What security and compliance certifications does Hygraph have?
Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications demonstrate Hygraph's commitment to security and data protection. See security details.
Getting Started & Onboarding
How easy is it to get started with Hygraph?
Hygraph offers a free API playground, a free forever developer account, and a structured onboarding process with introduction calls, account provisioning, and technical/content kickoffs. Extensive documentation and training resources (webinars, live streams, how-to videos) are available to help you get started quickly. Explore documentation.
Support & Community
What support options are available for Hygraph users?
Hygraph provides 24/7 support via chat, email, and phone, real-time troubleshooting through Intercom chat, a community Slack channel, extensive documentation, and training resources. Enterprise customers receive a dedicated Customer Success Manager. See support resources.
Additional Resources
Where can I find more documentation about enumerations, components, and references in Hygraph?
Official documentation is available for enumerations, components, and references to help you implement and customize your schema effectively.
This guide shows how to build a card grid component that uses reference fields to relate content to an entry.
This card grid contains a number field so you can indicate how many columns the grid should have, a reference field that lets you relate content entries in your project as cards, and dropdown menus to select the size of the gap between cards and the theme.
Here is an example that shows how this card grid could potentially look on your frontend:
Example card grid
It is a good option when you need to show content entries in your project as cards. A good example of this would be a card grid showing related entries, such as products.
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.
OPTION 1:Create a project. This is the way to go if you want to follow the entire tutorial for learning purposes.
OPTION 2:Clone the cookbook project. This is the way to go if you're curious about how the card grids are made but don't want to follow the step-by-step creation process. This project contains the entire Card Grid Cookbook so you can compare them, or look into what instances they contain.
OPTION 3:Use an existing project of yours. If you have a project already and want to add this card grid to it, this is the way to go. In this case, you may need to adjust parts of the tutorial to your own project schema.
Take plan limits into consideration when adding a recipe to your own project.
Enumerations: An enumeration is a predefined set of values that represents a list of possible options. You can use them to group values within a type.
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 use it to create related content from the content creation screen.
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.
Path 1: Use this guide to create a card grid component that you can reuse across different models in your Hygraph projects.
Path 2: Clone the project that contains the entire Card Grid cookbook to compare the different card grid configurations without having to clone multiple projects.
This cookbook contains all the recipes we have so far to create card grids, so you can compare the different card grid configurations without having to clone multiple projects.
To find this particular recipe in the cookbook project, navigate to the schema and look for "Card Grid - References".
This project also contains a demo model that includes all the card grid components in the cookbook as basic component fields, as well as a modular component field that you can use as a card grid type selector.
Before we can build components, we sometimes need to create other schema elements that will later be added to those components as instances. We will divide this process in steps to make it more manageable:
Create the enumerations: We will need to create enumerations so that we can later on use dropdown menus to select different styling options.
Create models: We will create three models so that we can select them as referenceable by the grid.
Create the card grid: Finally, we'll combine all the elements we worked on before to our card grid.
We will start by creating an enumeration that we can later add to our card grid component as a dropdown menu to select the gap size between our cards on the grid.
We'll navigate to our project schema,click +Add next to Enumerations, and use the following information to create our enumeration:
Field
Input
Display Name
Cards gap
API ID
CardsGap
We'll click Add enumeration to save.
Card grid with references - Cards gap enumeration
Next, we need to add enumeration values. For every enumeration value, we need to enter a Display name, an API ID, and click Add.
We'll add the following values:
Display name
API ID
Large
large
Medium
medium
Small
small
Finally, we'll click Add enumeration to save.
Card grid with references - Cards gap enumeration values
This card grid configuration will use references to link entries from models in our schema.
Pro Tip
In a real situation, you would use actual content models that you planned and built for your project, but for the sake of this example, we will simply create three empty content models so we can later on reference them.
Field
Input
Display Name
Product
API ID
Product
API ID Plural
Products
Card grid with references - Models
We'll click Add model to save.
Next, we'll create our second content model using the following information:
Field
Input
Display Name
Blog
API ID
Blog
API ID Plural
Blogs
We'll click Add Model to save.
And one final time for our third model:
Field
Input
Display Name
Store
API ID
Store
API ID Plural
Stores
We'll click Add model to save.
These are the three content models that we will include in our reference when we create the card grid.
At this point, we've created everything we need in order to start working on our card grid component.
We'll click +Add next to Components and use the following information:
Field
Input
Display Name
Card Grid - References
API ID
CardGridReferences
API ID Plural
CardGridReferencess
Card grid with references - Component
We'll click Add component to save. We can now start adding instances to this component.
Let's start with a Number field, which we can later use to indicate the number of columns on our grid.
We'll find it on the Add fields right sidebar, click on it, and use the following information:
Tab
Field
Input
Settings
Display Name
Columns
Settings
API ID
columns
Validations
Make field required checkbox
Select this checkbox
Card grid with references - Number of columns
We'll click Add to save.
Earlier, we created three empty content models. We will now add them as part of a Reference field so when we use the card grid component, we will be able to relate content entries from those models. The entries we reference will be included as cards in our grid.
We'll find the Reference field on the Add fields right sidebar, click on it, and use the following information:
Tab
Field
Input
Define
Reference type
Select Allow multiple models to be referenced (Union Type)
Define
Models to reference
Use the dropdown menu to select Product, Blog and Store
Define
Reference direction
Select One-way reference
Define
Allow multiple... checkbox
Select Allow multiple Product, Blog, Store per CardGridReferences
Configure reference
Display Name
Cards
Configure reference
API ID
cards
Card grid with references - Reference field
We'll click Add to save.
In the case of this reference field, we created a one-way reference because we don't want to create a reverse field in the models we created earlier; and we allowed multiple values because without that we'd only be able to add a single card to our grid.
The final step will be to add Enumeration fields so we can later select the gap size between cards and the theme.
Let's start with the gap size. We'll find the Enumeration field on the Add fields right sidebar, and use the following information to create it:
Tab
Field
Input
Settings
Display Name
Cards gap
Settings
API ID
cardsGap
Settings
Enumeration
Select "Cards gap" from the dropdown menu
Card grid with references - Gap
We'll click Add to save.
Finally, we'll repeat the process to add the theme enumeration field:
Tab
Field
Input
Settings
Display Name
Theme
Settings
API ID
theme
Settings
Enumeration
Select "Theme" from the dropdown menu
Card grid with references - Theme
We'll click Add to save.
We've created a card grid component that contains several schema elements for customization purposes and that lets us add existing content entries as cards.
Card grid with references
This guide helped you create the schema element yourself. Alternatively, you can clone a project containing all our card grid recipes.