When building the data structure of an application, you need to create collections to manage your blog posts, your products, or any type of content that will be repeated. This feature has been available in Strapi for quite a long time.
But managing content that will have only one instance in your project is also highly requested by Strapi users - for example, your menu, a static page, or a footer. Being able to manage Single Types is essential and this is why we are delighted to announce today the release of Strapi beta.19, including the Single Types feature.
Let's explain what this feature is about, how to use it with a step-by-step typical user journey and you'll be able to install and play with it for your own project!
What are Single Types?
Single Types is one of these features that facilitates content management. They are handy to manage content like a homepage, an About us page, or any other type of content that is not part of a collection. It is also helpful for managing global settings, like SEO settings.
Think of all the specific parts of your app that you need to set up only once. Your menu, your footer. This feature is made for them. Let's see how Single Types are managed in Strapi and how you can take advantage of this new feature for your projects.
How to use single types in Strapi?
In this example, we are going to create an About Us page containing a hero section with a cover image, a content section with texts and pictures, and a footer, looking like the Foodadvisor About us page: https://foodadvisor.strapi.io/about
1. Creating a single type.
Creating a single type is as easy as creating a collection type.
To do so, you need to navigate to the Content Type Builder and create a Single Type from the sub-menu. So let's go ahead and create our About-us Single Type. We need to add the following fields to match our example page on Foodadvisor:
- Cover image
- Page Content
A Single Type section has now appeared, containing the Single Type About. The 2 sections allow differentiating Single Types from Collections Types, for a more comfortable authoring experience.
You probably also noticed that when we named the Single Type, the next field in the modal was auto-filled with content. This field is the other new feature in this release: the UID field.
2. Adding a UID field
The UID field is a unique identifier that can be used to identify your type. The most common use case is to create SEO-friendly website URLs.
This field requires to enter a lowercase, space-free unique id such as about-us. But don't worry about errors, we got your back: the field will first auto-populate with the name you chose for the Single Type, all spaces replaced with hyphens. But you can also decide to manually add a UID field in your Single Type, and link it to the field of your choice.
In our example, we will add a UID field Slug in the Single Type About, and link it with the Title field that we already created. That way, if the Title of the page is actually The Team, we will be able to have an SEO friendly URL looking like this: https://foodadvisor.strapi.io/the-team.
Each Single Type that contains a UID field must have a unique value for this field. This ensures that all your URLs are unique.
3. Configuring the Single Type view.
As engineers, when you build the content model of an application, you are determining the content author experience for months or years. So each page or content types must be easy to access and configured as it should. This is why in Strapi, you can set the view and change the order of the fields as you want.
If you are familiar with Strapi, you probably already know this, as it is strictly similar to the Collection Types configuration page.
4. Switching between Single Types and Collection Types.
Single Types can only have one-to-one or one-to-many relations with Collection Types, as they are Single Types. They can easily be switched to Collection Types (by clicking on the editing pen next to the Single Type name).
Collections Types can also be switched to Single Types, only if they have no relational incompatibility (like a many-to-many relation field).
Single Types can be switched to Collections Types and the other way around as long as they have no relations set with other Content Types.
In our example, we created a Collection Type Blog Post that contains a Relation field many-to-many. Switching it to a Single Type doesn't work unless we change the relation field value to one-to-one.
Upgrade to beta.19
If you are new to Strapi, just give it a try!
Take a look at the Getting Started guide to jump on board, or get started with the following command line:
yarn create strapi-app my-app
Check out our public product roadmap to see what features we'll be working on next.
News in your inbox
Did you enjoy this article? Subscribe to get the latest posts and the most important updates!