Define a Content Model
Now that we have a working Craft installation, it’s time to explore some of its powerful content modeling features.
In this section, we will:
- Review Craft’s native content types;
- Create a space to author blog posts and add custom fields;
- Define some globally-available data;
- Add a one-off “About” page;
- Draft and publish some content;
# Content Types in Craft
Craft provides a number of distinct building blocks, each appropriate for different kinds of content. Let’s take a quick look at a few of them that will be particularly useful in building a blog.
We use the term elements to collectively describe the variety of content types Craft comes with. Plugins can provide their own element types, as well!
Entries are the most versatile type of element. Every entry belongs to a section, which determines how administrators will use them. Entries have titles, authors, post dates, and expiry dates.
Sections come in three flavors: Channels, Singles, and Structures. These section types share many features like field layouts, template mappings, customizable URL patterns, localization, and more.
A channel is typically used to syndicate many entries with a similar composition, sorted by one or more of their built-in attributes or custom fields. Channels can have multiple entry types to further distinguish, filter, or sort entries. Each entry type is given its own field layout.
Example: Articles, events, classifieds, employee profiles.
Singles are for one-off pages: there will only ever be one entry type (and entry) per single. URLs of singles can be locked to prevent tampering.
Example: Homepage, a blog landing page, featured case studies, or an “About” page.
Structures support the same features as channels, but add the ability to nest entries within other entries—and to define their order in relation to one another. The hierarchical nature of structures makes them a good candidate for complex bundles of information, or for situations where the order of pages is important.
Example: Reference libraries, sequential tutorials, multi-page case studies.
# Entry Types
Channels and structures can define multiple entry types. In doing so, you can create rich variations in authoring experience, even within a section—or differentiate entries in the front-end with features and styles appropriate to the content.
In situations where you need to manage some information that isn’t associated with a single page (or that might be accessed in many places throughout a site) globals are the answer. Globals are a lot like singles, except they do not get their own URLs.
Each global set has its own field layout, and can use any of your custom fields. Globals are always within reach, under a main navigation item.
Example: Navigation, sidebars, footer or header content, or non-critical “settings” you want controlled by a user (like an analytics ID).
Assets are Craft’s way of managing uploaded files. They’re stored on filesystems, and organized into groups called volumes, which can have any number of nested folders. In addition to keeping track of the underlying file, Assets are elements just like entries: each volume defines a field layout, allowing you to attach rich custom field data.
Craft also includes a browser-based image editor, which supports cropping, rotating, flipping, and setting “focal points.” These tools can be used in conjunction with Craft’s sophisticated image transform system to generate and deliver highly-optimized variations on images for your front-end.
# Custom Fields
Your content model is defined by the union of element types’ native properties and whatever custom fields are attached to them via field layouts. Craft comes with a number of powerful field types, out-of-the-box:
The specifics of each field aren’t important just yet—we’ll take a closer look at a few of them in just a moment.
There are loads more field types available in the official Plugin Store (opens new window).
# Modeling a Blog Post
As our first exercise in content modeling, let’s consider what comprises a blog post:
- Post Date
- Feature/Summary Image
From the element types and fields we’ve learned about so far, we might map these features into Craft concepts, like this:
- Blog posts will be entries, which natively support:
- Post Dates;
- Feature images will be uploaded as assets;
- Summary text can live in a Plain Text field;
- Categories can be handled with Craft’s element type of the same name (we’ll learn about this as we set it up—categories are very similar to entries);
- Post content will be managed as repeating blocks with a Matrix field;
This process may seem arcane at first—once you’ve had a chance to see the tools in action, connecting them to your project goals will feel less mechanical and more creative.
Let’s dive in to the Settings screen of the control panel!