Content Models and Content Entries
In this lesson, we'll explore the foundational concepts of Webiny Headless CMS: content models and content entries. Understanding these concepts is essential for working with any headless CMS, and Webiny provides a powerful and flexible implementation.
In this lesson...
Here are the topics we'll cover
What content models are and how they work.
Understanding content entries.
The relationship between models and entries.
What Are Content Models?
A content model is a blueprint or schema that defines the structure of your content. Think of it as a template that specifies what fields your content will have and what type of data each field can contain.
Content models are similar to:
- Database tables in traditional databases (defining columns and their types)
- Classes in object-oriented programming (defining properties and their types)
- Schemas in GraphQL (defining types and their fields)
Example: Blog Post Content Model
Let's say you're building a blog. Your "Blog Post" content model might include:
- Title (Text field)
- Slug (Text field)
- Author (Reference to an Author model)
- Featured Image (File field)
- Body (Rich text field)
- Category (Reference to a Category model)
- Tags (Multiple references to a Tag model)
- Published Date (DateTime field)
- Is Featured (Boolean field)
This model defines the structure, but it doesn't contain any actual blog posts - it just defines what a blog post should look like.
Content models are reusable blueprints. Once you create a "Blog Post" model, you can create hundreds or thousands of individual blog posts (entries) based on that model.
What Are Content Entries?
A content entry is an instance of a content model - it's the actual content created using the structure defined by the model.
Using our blog post example:
- The content model defines what fields a blog post has (title, body, author, etc.)
- Each content entry is an actual blog post with real values for those fields
Example: Blog Post Entries
Based on the "Blog Post" model above, you might have entries like:
Entry 1:
- Title: "Getting Started with Webiny"
- Slug: "getting-started-with-webiny"
- Author: "John Doe"
- Body: "In this post, we'll explore..."
- Published Date: "2024-01-15"
Entry 2:
- Title: "Advanced Headless CMS Patterns"
- Slug: "advanced-headless-cms-patterns"
- Author: "Jane Smith"
- Body: "Let's dive into advanced patterns..."
- Published Date: "2024-01-20"
Each entry contains actual data that follows the structure defined by the model.
The Relationship Between Models and Entries
The relationship is straightforward:
Content Model (Blueprint)
↓
Content Entries (Instances)
- One model → Many entries
- The model defines the structure
- Entries contain the actual data
Think of it like a form:
- The model is the blank form template
- Each entry is a filled-out form
Content models are like cookie cutters - they define the shape. Content entries are like the actual cookies - each one has the same shape but different flavor, size, or decorations.
Field Types in Webiny
Webiny provides a rich set of field types you can use in your content models:
Basic Fields
- Text - Short text (single line)
- Long Text - Multi-line text
- Rich Text - Formatted text with headings, lists, links, etc.
- Number - Numeric values
- Boolean - True/false values
- DateTime - Dates and times
Advanced Fields
- File - Upload and reference files (images, PDFs, etc.)
- Reference - Link to entries from other models
- Object - Nested field groups
- Dynamic Zone - Flexible content blocks (great for page builders)
List Fields
Most field types can be configured as lists (arrays) to store multiple values. For example:
- A list of tags
- Multiple authors
- A gallery of images
Why This Matters
Understanding content models and entries is crucial because:
- Structure First - You define your content structure (models) before creating content (entries)
- Type Safety - Models ensure your content has the correct structure and data types
- API Generation - Webiny automatically generates GraphQL APIs based on your models
- Validation - Models define validation rules that entries must follow
- Reusability - One model can be used to create thousands of entries
When you create a content model in Webiny, the system automatically generates GraphQL queries and mutations for creating, reading, updating, and deleting entries. You don't need to write any backend code!
Content Models in Practice
In the real world, you might have content models for:
- E-commerce: Product, Category, Brand, Review, Order
- Blog: Post, Author, Category, Tag, Comment
- Documentation: Article, Section, Code Example, Tutorial
- Marketing: Landing Page, Feature, Testimonial, Case Study
- Media: Video, Podcast, Episode, Playlist
Each of these models would define the structure, and you'd create individual entries for each product, blog post, article, etc.
What's Next?
Now that you understand the basics of content models and entries, you're ready to:
- Learn about content versioning (next lesson) - how Webiny tracks changes to your entries
- Create your first content model through the UI
- Create content models via code for more complex scenarios
- Query your content using the GraphQL API
It's time to take a quiz!
Test your knowledge and see what you've just learned.
What is the relationship between a content model and a content entry?
Summary
Content models and entries are the foundation of Webiny Headless CMS:
- Content models are blueprints that define structure and field types
- Content entries are instances containing actual data
- One model can have many entries
- Webiny provides rich field types for building flexible content structures
- Models automatically generate GraphQL APIs
Understanding this relationship is essential for everything else you'll do with Webiny's Headless CMS. In the next lesson, we'll explore how Webiny handles content versioning to track changes to your entries over time.