Contentful logo

Contentful Community

A content type for one entry only

Hello, everyone

This is my first time setting up a space for my project. I have Home Page and Page Footer content types which each only has exactly one active entry at any given time.

Is this an antipattern in Contentful?

Hi @trirawibowo,

As a general rule, I would recommend against building your content models to reflect the layout of your website. Think of content models as the foundation that structures data semantically, and the layout as the tip of the iceberg that is merely one of the many possible ways to display the same data.

Having said that, so called “singletons” i.e. content models that can have only one instance, is indeed a feature requested by many and I can think of several valid use cases for it. However, in your case it might not be the best solution. For example…do Page and HomePage really have any difference when it comes to field structure? How about instead adding a field to Page model that marks it as the home page.

Hi,

Thank you for your response. My initial understanding was not to make a content model for specifically a single page but after some tinkering, I came to realize that such “singleton”, although I found it contradicting database normalization, was actually quite fitting for Contentful as a CMS in my opinion.

In my case, I don’t have a generic layout that is applicable for every page. Some of them are based on the same layout but the home page has its own. Therefore, making a generic Page content model is not what I need as far as I understand.

I have been thinking on Contentful’s lack of “singleton” content types for things like global site settings and similar. It does seem like the App framework could potentially be a solution here. A custom App could have a Footer Content field on the configuration page that could be used in your consumer application. The downside here is that the only way to consume the app installation parameters is with the Contentful Management API/SDK, I don’t think there’s a way to get them through the Delivery API.