We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Accept
Improve your Craft CMS skills

A Guide To Adding And Updating Entry Types On Craft CMS

10 min read
Shape April 2022 HR 202

Struggling to leverage the power of entries in Craft CMS? Entry types define the structure for your content, but configuring them right takes skill. This guide provides pro tips for Craft users of all levels to master creating, updating and displaying entries through optimized entry types. Learn how to troubleshoot issues and take your entries to the next level with the flexibility of Craft's field layouts and templates.

Entry types in Craft CMS define the structure and fields for entries within sections. You can customize entry types with different field layouts and settings to model flexible content structures. Careful planning of fields, relations, validation, and display settings allows optimizing entry types for editing, performance, and output.

Entry Types in Craft CMS

Defining Entry Types

Entry types are a core concept in Craft CMS that define the structure and content model for entries. When you create a new section in Craft, you must assign it an entry type which will determine what fields and content can be captured in the entries belonging to that section.

So in simple terms, entry types set up the blueprint for the entries in a section. They allow you to customize the fields needed to store your content, ranging from plain text and images to complex matrix fields or relational references. This enables flexible and reusable content modeling.

For example, you could have an "Article" entry type with fields for the article title, summary, author, body text etc. And a separate "Event" entry type for event entries with fields for the event name, date, location etc. The entry type defines the shape of the content.

By associating sections with specific entry types, Craft CMS allows for structured content management. You can have multiple sections using the same entry type for consistent content, or sections with customized entry types tailored to their content requirements.

Benefits of Entry Types

Entry types provide several advantages that enable more flexible and structured content management in Craft CMS:

  • Customizable Content Modeling: You can create entry types with completely customized field layouts and content structures without being limited to predefined content models. This allows for flexible and versatile content management suitable for diverse sites and applications.

  • Reusable Structures: Entry types are reusable. Once created, they can be assigned to multiple sections enabling consistency and efficiency. For example, you can have a common "Article" entry type used across your News, Blog and Articles sections.

  • Separation of Structure and Content: Entry types separate content structure from content. The fields and structure are defined once in the entry type. The actual entry content is then created separately in section entries based on the associated entry type.

  • Better Organization: Entry types allow for better organization of content. Sections and entries with common purposes can leverage the same entry types. While sections with different content needs can have their own custom entry types.

  • Easier Content Modeling: Craft CMS provides a user-friendly UI for managing entry types and associated fields without the need for complex database schema layouts. This enables easy content modeling for end users.

How Entry Types Work

Here is a quick overview of how entry types work in Craft CMS:

  • Entry types are created as their own entities separate from sections and entries. You can create any number of entry types to account for the different content structures needed.

  • When creating a new section, you assign one of the available entry types to that section. This entry type then defines what content can be captured in entries within that section.

  • The entry type consists of various fields that represent the structure of entries in that section. These can be simple text and image fields or complex matrix blocks, categories and relations.

  • New entries added to the section will then have the fields defined by the associated entry type. The content creators can populate these fields with the actual entry content.

  • So in summary, the entry type acts as a template for entries by defining the fields available. The section associates itself with the entry type. Entries get created within the section using the structure in the entry type.

  • This separation of concern between structure, content and presentation allows for very flexible content modeling. Entry types can be reused across sections. And the same entry type can result in different presentation by tweaking the templates.

So in Craft CMS, entry types define the shape of the content, sections associated with entry types and the actual content gets created in entries. This provides a clean separation between structure, content and display. And enables very powerful and flexible content modeling capabilities.

Creating New Entry Types

Entry Type Settings

When you go to create a new entry type in Craft CMS, you will need to configure some important settings that define how the entry type will work. The most essential settings to focus on are:

the Name, which will be the label that identifies this entry type in the CMS; the Handle, which is a unique ID that will be used for coding purposes; the Section, where you assign which section this entry type should apply to (or "All" sections); and the Title Format, where you define the default title structure for entries using this type.

It is recommended to use clear, descriptive names and handles that reflect the content that will be captured. Also associate the entry type with the most relevant section upfront, keeping in mind you can reuse it across sections later if needed. The title format can always be tweaked down the road as well. Taking the time to set up the core entry type settings thoughtfully will ensure you have a solid foundation for structuring your content.

Adding Custom Fields

One of the most important parts of an entry type is the custom fields you add to capture content. Craft provides an extensive selection of field types you can choose from to tailor the entry type for its intended purpose. For example, basic text fields are perfect for titles, summaries, and other text-based content. Dropdown and radio button fields allow selecting from predefined options, while checkboxes work for boolean or multi-value fields.

Rich text fields provide full HTML content editing for longform content like body text. Number and date/time fields capture numeric values or dates. Table fields add tables with rows and columns within entries. Asset and file fields associate file uploads like images. You can make fields either required or optional as needed - required fields must be filled while optional ones can be left blank. The range of field types in Craft allows you to capture diverse content in structured ways through custom entry types.

Organizing With Field Layouts

To organize the various fields in an orderly fashion, Craft provides a "Field Layout" tab when editing entry types. Here you can use tabs and collapsible sections to group related fields together in logical ways. For example, you may put basic fields like the title and summary in a "Content" tab, media fields like images and videos in a separate "Media" tab, and SEO or meta fields in an "SEO" tab. Collapsible sections can further help group loose related fields within tabs.

Some best practices are to use intuitive tab names based on field purpose, position important common fields like title prominently, and arrange fields in order of usage with frequently used ones first. Keep the number of tabs limited to 2-3 for scanability, and aim to balance fields across tabs. Taking the time to thoughtfully organize your fields in a clean layout will result in an easy-to-use editing experience for content creators.

Working With Entry Type Fields

Common Field Types

What is Craft CMS? Craft CMS provides an extensive selection of field types that can be added to entry types for capturing content. Some of the most common are:

Text Fields - For plain text, titles, summaries etc. Can control formatting, characters limits, validation etc.

Rich Text - For full HTML content like body text. Comes with a WYSIWYG editor.

Number - For numeric values like scores, quantities, percentages etc. Can set value range.

Dropdown - For selectable dropdown options. Can be a single or multi-select.

Checkboxes - For boolean Yes/No values or multi-value selection.

** Date & Time** - For date, time or datetime values. Provides validation and formatting options.

Assets - For associating uploads like images and files. Can set allowed file types.

Categories - For relating entries to pre-defined categories. Useful for tagging.

Table - For adding tables with rows and columns within entries.

Matrix - For repeatable blocks of nested fields, like an FAQ or pricing table.

The field types above allow capturing all kinds of structured content within entry types, from plain text to assets, categories and complex nested structures.

Managing Field Settings

Each field comes with various settings you can configure:

Labels - Define the field label seen by editors. Should be descriptive.

Instructions - Additional instructions that appear under the field. Help provide guidance.

Required - Makes the field mandatory. The entry won't save without a value.

Translation - Allow field values to be translated for multi-language sites.

Default Value - Prepopulate a default value for new entries. Can improve consistency.

Some best practices are to use clear labels, provide useful instructions for complex fields, appropriately set required fields, enable translation if needed, and define default values for consistency.

Taking the time to correctly configure field settings results in a smoother editing experience for content creators.

Field Organization Tips

When adding multiple fields to an entry type, you can organize them into a logical structure using Craft's field layout options:

Group Related Fields - Fields like title and body text can go together under a "Content" section. Asset fields under "Media". Related fields should be grouped.

Arrange by Order of Use - Frequently used fields near the top. Optional ones lower down. Helps focus the editor.

Create Tabs for Long Forms - Use tabs to break up field groups over multiple screens for lengthy forms.

Similar Field Types Together - Group several text fields together rather than intermixing field types. Improves scanability.

Introduce Collapsible Sections - Collapsible field groups help organize related loose fields within tabs.

Watch Tab Length - Balance fields evenly across tabs. Don't overload a single tab.

Limit Tabs - Too many tabs can get confusing. Try to stick to 2-3 tabs max.

Using these tips will help you craft field layouts that make it easy for editors to find fields and intuitively enter content. Structured organization improves efficiency.

Relating and Structuring Entries

Entry Structures

Craft allows you to organize entries in hierarchical structures using a parent-child relationship model. The "Structure" settings when creating a section control how its entries are structured.

The structure can be set to:

  • Single - Flat with no hierarchy. All entries at one level.

  • Hierarchy - Entries can have nested children entries in a tree model.

  • Matrix - Child entries are ordered manually rather than by hierarchy.

Structures allow building nested relationships between entries. For example, you can have a parent "Guide" entry with many child "Tip" entries nested under it.

Display order and depth settings control how structured content is presented in templates. Craft provides utilities for traversing and displaying hierarchical entry structures.

Overall, structures provide a powerful way to model complex content relationships beyond flat entries through parent-child nesting.

Creating Entry Relations

While structures model explicit parent-child relationships, Craft's relational "Entries" field type allows creating loosely coupled connections between entries.

The Entries field enables selecting one or more related entries within a field. This provides flexibility to relate entries without the rigid hierarchy of structures.

For example, you can link between stories in a news section, associate recipes with related dishes, or connect product entries to their accessory products.

Relations make it easy to associate connected but separate pieces of content. Frontend templates can fetch and display these complex relations between entries.

Unlike hierarchical structures, relations allow modeling more real-world connections between content.

Managing Structured Content

In the Craft CMS control panel, structured sections with nested entries display in hierarchical trees. Parent entries can be expanded to show child entries, allowing browsing the content relationships.

Tree views make it easy to navigate and manage structured content organizations. Child entries can be reordered by dragging and dropping within parents. The structure is maintained completely on the admin-side.

The "Entries" index page also displays parent columns for hierarchical entries. This provides an overview of where entries exist in the content structure, regardless of the current tree view.

For matrix structures, entries are reordered manually using the "Position" attribute rather than by hierarchy. But they can still be nested under parents.

Overall, Craft provides intuitive interfaces for managing structured content models based on hierarchies, matrices or relational connections. Structures take content organization beyond just flat entries.

Displaying and Outputting Entries

Entry Display Settings

Craft provides several ways to customize how entries are displayed in both the control panel and front-end:

View Modes - Control Panel view modes alter what fields are visible for different contexts. For example, the "Raw content" mode shows unprocessed field values.

List Settings - Customize what columns, details, and buttons show on entry index pages. Optimize for key details.

Output - Choose what fields output on front-end templates and their order. Useful for optimization.

Titles - Set dynamic entry titles that format values from fields. For example, title + post date.

Using display settings allows tailoring entry output for the control panel and front-end templates based on what details are most relevant for content creators and site visitors.

Entry Templates

On the front-end, Craft loads a template to display entry content. There are two types of entry templates:

Global - Templates stored as entries/_entry for all entries across sections. Best for common handling.

Local - Section-specific templates like news/_entry just for local customization. Override global.

Local templates take precedence over global ones. Common logic can go in global templates, with sections providing any custom overrides needed in local templates.

Entry variables like entry.title and entry.myField provide access to content. Combine templates, variables, and display settings for complete output control.

Advanced Display Options

Craft provides additional advanced options for customizing entry output:

Element API - For directly fetching entries via API rather than Twig templates. Offers more flexibility for JavaScript apps.

Query Parameters - Fetch only specific fields, related elements, etc. for simpler queries. Improves performance.

Slice Tool - Prune extra fields from entries for cleaner HTML. Useful for RSS feeds.

Lightswitch - Fetch entries in "lite" mode without extra metadata for speed. Good for indexes.

Filter and Format - Transform field values dynamically using filters and formatting rules.

Pagination - Paginate long lists of entries rather than huge chunks. Improves frontend experience.

Using the advanced options expands the possibilities for tailoring entry output beyond basic templates. Craft provides powerful and flexible tools for outputting entries exactly as needed for projects.

Editing and Updating Existing Entry Types

Modifying Settings

For existing entry types that already have associated entries, you can modify certain settings right from the control panel:

Name - Change the entry type name to something clearer if needed. Existing associations remain intact.

Handle - The handle can be updated as well while retaining links to entries.

Section - Section association can be changed or set to "All sections". May impact templates.

Title Format - Update the title format settings to alter default entry titles.

Template Path - Switch the template path to use different output templates.

Those are the settings that can safely be edited on existing entry types without affecting content. Avoid changing the handle if possible since it can break references.

Changing Field Layouts

The field layout on an entry type can also be updated after it already has entries:

Add New Fields - Adding new fields to capture additional content is perfectly safe. New entries will see the new fields.

Remove Fields - Removing unused fields helps declutter the editor. Existing data will be retained in the database.

Rearrange Layout - Fields can be freely reordered and grouped into new tabs/sections.

Modify Field Settings - Things like instructions and labels can be updated. Just avoid changing handles.

Replace Fields - Swapping one field for another can be done carefully using the same handles and settings.

Modifying field layouts gives flexibility to improve the content editing experience. Craft safely retains existing data even as the entry type evolves.

Handling Content Migrations

When making substantial changes to an entry type, for example removing or replacing fields, some content migration may be required:

  • Removing a field will retain its data but just not show in the UI. The data can be extracted if needed.

  • If a field handle or settings change, existing data may need to be migrated to the new field manually via scripts.

  • Adding structural changes like new tabs may require adjusting templates to avoid output issues.

  • Renaming a field’s handle could break references in code and templates that need updating.

The Craft team recommends setting up a test or staging environment to trial migration impact before modifying production entry types. Backups are also useful for rolling back issues.

With some care, entry types can be evolved via iterative improvements over time while retaining existing content through any migrations required.

Advanced Entry Type Topics

Localization

For multi-language sites built with Craft CMS, entry types provide powerful localization capabilities to manage translations for both the entry type itself and the content. By enabling "Site locales" on an entry type, separate translated versions can be created for field labels, instructions, and other textual elements in each defined site locale. This allows content creators working in different languages to get a natively localized data entry experience.

The entry content also becomes localizable, with the ability to provide translated field values per locale. The localized versions are tied together behind the scenes so that Craft outputs the appropriate language for the active site locale. Overall, localizing entry types in this way bridges content creation across multiple languages, while still allowing custom translations tailored to each audience. It removes friction in the editing process so content authors can focus on providing the right content for each locale.

Validation and Required Fields

To enforce business rules and validate submitted data, entry types give you several options. Individual fields can be set as required, forcing editors to provide a value. Validation rules can check the values against expected formats, lengths, regex patterns, or custom PHP code. Live validation warnings and errors display instantly during editing and submission if any issues are detected. Default values and handy instruction text can further guide editors to provide content in the appropriate structure.

Together, these validation mechanisms ensure the entered content matches the data types and formats needed for a smooth experience across the project, reducing cleanup work down the road. Setting expectations through validation helps maintain clean structured content. Front-end form validation provides an additional safety net before data hits Craft.

Automation and Integrations

The structured schemas defined by entry types enable integrating Craft content across many systems through automation and APIs. Options like webhooks, workflows, Element API, headless CMS, and CRON jobs allow building custom experiences powered by your structured entry data. Entry types provide the reliable content model that integrations can interface with across platforms. The flexibility of Craft plus the consistency of structured entry types opens the door for all kinds of creative integrations and automations between your content and external services.

Managing Entry Type Performance

Optimizing Queries

When working with entry types containing large datasets or complex relations, optimizing the database queries becomes crucial for site performance. Techniques like enabling eager loading for relations fields and selecting only the specific fields needed can dramatically improve query times by avoiding expensive lazy-loading and full element queries. Pagination with limit and offset parameters prevents pulling huge batches of entries at once. Status, search, and enabledForSite filters narrow datasets down just to the relevant subsets needed.

Setting the "with" parameter judiciously to only include essential related elements eager-loads the correct relations without triggering cascading bloat. And caching frequently accessed element queries prevents repeat hits to the database. Following these query optimization best practices allows Craft to rapidly deliver lean, optimized entry data to the front-end templates for smooth performance.

Caching Strategies

In addition to optimized queries, comprehensive caching strategies take performance to the next level for public and high-traffic sites. Built-in fragment caching provides full-page caching of entire templates.

More advanced solutions like Redis and Craft plugins enable granular caching tailored to entry data. Identifying dynamic tags with the {% cache %} tag excludes them from caching for continued currency. Proper cache expiration times ensure stale data doesn't linger.

And purging caches on entry updates maintains accuracy. CDN caching adds geographical distribution for lighting fast cache access worldwide. The combination of caching techniques eliminates repeated database queries and keeps sites fast.

Image Optimization

For asset fields attached to entries, images can be optimized for performance through transformed image generation, lazyloading, compression, CDN delivery and deferment.

Craft auto-generates resized and optimized image transforms on demand, while lazyloading defers offscreen image loads until visible. Delivering images through a CDN improves geographical speed. Setting appropriate compression levels keeps originals lean.

And solutions like defer.js allow prefetching images as needed. Together, these approaches serve up optimized, lightweight imagery for blazing fast visual performance across entry-driven sites.

Troubleshooting Entry Types

Debugging Errors

When entry types exhibit bugs or unexpected behavior, following some core troubleshooting practices can help identify the issue. Checking the Craft logs for any entry type or field-related errors provides the full details on exceptions being thrown. Temporarily disabling plugins isolates potential conflicts, while clearing caches rules out stale data. For elusive 500 errors, stepping through with Xdebug or logging helps pinpoint the source. On the front-end, browser developer tools can reveal JS issues and inspect network requests. Increasing PHP error reporting also helps debug template problems during rendering.

If duplication errors arise, renaming the entry type handle disambiguates it from identically named types. And reproducing with various debugging approaches enabled finally allows narrowing down the specific root cause. Following this methodical process helps resolve entry type errors.

Field Troubles

Troubleshooting misbehaving fields requires careful inspection of the field configuration. Vanished fields may have been accidentally removed from the layout, while missing submitted values could indicate a template handle mismatch. Reviewing validation rules ensures settings aren't incorrectly blocking saves, and clearing field caches rules out stale settings.

For overlapping fields, adjust the layout structure. Audit handles to catch any incorrectly typed ones pulling in unrelated data. And consider disabling deletion for structurally critical fields.

Checking the field change history provides clues to anomalies. Meticulously examining field settings isolates the cause of issues.

Relations Debugging

Relation problems can arise in complex configurations. Circular relations creating loops prevent entry saving, while typos in field handles lead to missing or incorrect related entries. Confirming the field definitions match on both sides rules out disconnects. Cascade deleting can help preserve relations if entries are deleted. Eager loading avoids failures from separate lazy queries.

Reviewing the relation field type and target settings validates proper configuration. Structural issues may require inspecting the field layout matrix for odd configurations. And failed propagation across relations points to bigger underlying problems. Carefully auditing and simplifying overly complex relations helps resolve issues and avoid future headaches.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Share
Feedback
Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat