Skip to content
Geecon Global
Book a consultation (opens in a new tab)
Menu

How to model reusable content in Contentful

Amol Agre (opens in a new tab), Technical Lead

Published · Reviewed · 6 min read

Direct answer#

Model each reusable piece of content as its own content type, named for what it means rather than where it appears, and link to it with reference fields that only accept the content types you intend. Add validations so editors cannot publish incomplete or inconsistent entries, and localise only the fields whose values genuinely change by locale, with fallback locales for the rest. Before you rely on shared entries, decide who may edit them, because a change to a shared entry shows up everywhere it is used.

Key takeaways

  • Model what content means, not where it appears on a page.
  • Restrict every reference and add validations, so mistakes fail at publish time rather than on the live site.
  • Keep nesting shallow, localise only what changes by locale, and control who can edit shared entries.

Steps or trade-offs#

Model meaning, not page layout#

The most common reason content cannot be reused is that it was modelled around a page design, which is why this is the first question in any content modelling exercise. A content type called "Homepage hero, left image" only fits one place. A content type called "Promotion" with a headline, summary, image and link can be used by a homepage, a landing page, an email or an app.

Let the content model describe what things are, and let each front end decide how to display them. A useful test: if a redesign would force you to rename or restructure a content type, it is describing layout rather than meaning.

Content types and fields#

A content type is a set of fields, each with a type such as short text, long text, rich text, number, date, location, boolean, JSON object, media or reference. Contentful's data model documentation describes up to 50 fields per content type, so a type that keeps growing towards that limit is usually a sign it should be split.

Practical guidelines:

  • Keep each content type focused on one concept: a person, a product, a promotion, a location.
  • Pull repeated chunks, such as an author bio or a legal disclaimer, into their own content type so they are written once and referenced many times.
  • Choose the narrowest field type that fits; a validated short text field stays cleaner than a long text field.

References: one or many#

Reference fields link an entry to other entries (or, for media fields, to assets). They come in two shapes: a single reference, for example an article's primary author, and many references, for example a list of related articles or the sections of a landing page. A many-references field also gives editors a sortable list, which makes it a natural fit for ordered page sections.

Always restrict which content types a reference field accepts. In the API this is the linkContentType validation; in the web app it is the option to accept only specified entry types. Without it, an editor can link a "Person" where your front end expects a "Promotion", and the page breaks at render time instead of at publish time.

Both shapes, with their restrictions, look like this in a migration script for the Contentful CLI. Defining the model in code lets you review it like any other change and apply it to each environment in turn:

// migrations/01-create-article.js
// Run with the Contentful CLI, against a sandbox environment first:
// contentful space migration --environment-id sandbox \
//   migrations/01-create-article.js
module.exports = function (migration) {
  const article = migration.createContentType('article', {
    name: 'Article',
    displayField: 'title',
  })
 
  article.createField('title', {
    name: 'Title',
    type: 'Symbol',
    required: true,
    validations: [{ size: { max: 120 } }],
  })
 
  // Single reference: exactly one author, and it must be a Person
  article.createField('author', {
    name: 'Author',
    type: 'Link',
    linkType: 'Entry',
    required: true,
    validations: [{ linkContentType: ['person'] }],
  })
 
  // Many references: an ordered list of up to six other articles
  article.createField('related', {
    name: 'Related articles',
    type: 'Array',
    items: {
      type: 'Link',
      linkType: 'Entry',
      validations: [{ linkContentType: ['article'] }],
    },
    validations: [{ size: { max: 6 } }],
  })
}

Reference or embed#

You have two main ways to place one entry inside another:

  • A reference field gives the relationship a defined position in the model. Use it when the relationship is structural: every article has an author, every page has an ordered list of sections.
  • An embedded entry in rich text places the entry inline within body copy, as a block or inline element. Use it when the position depends on the writing, such as a call-to-action halfway through an article. You can restrict which content types may be embedded, and you should.
Where should this content go?
  1. Does every entry of this type need exactly one, in the same place?

    Yes: A single reference field, such as an article's author

  2. Is it an ordered list of items, such as page sections or related articles?

    Yes: A many-references field

  3. Does its position depend on the writing, such as a call to action halfway through?

    Yes: An embedded entry in rich text

If every answer is no: It probably isn't reusable: make it a field on this content type

Embedded entries are still links. In the REST API they arrive as references with the linked data in the response's includes object. Contentful's client libraries resolve these for you, but the GraphQL API does not resolve references inside the rich text JSON automatically, so your code has to map them.

Nesting depth and the include parameter#

Every level of references adds work when you fetch content. On the Content Delivery API, a response includes the first level of linked content by default, and the include parameter sets how many levels to return, up to a maximum of include=10. Links are resolved against published content only, so a link to an unpublished entry is left out of the response and reported as an unresolvable link.

Four levels of references, and the include value that returns each one
  1. Page

    The entry you request.

  2. Section

    Linked from the page. Returned with include=1, the default.

  3. Card

    Linked from a section. Needs include=2.

  4. Person

    Linked from a card, for example its author. Needs include=3.

So keep nesting shallow (page, section, card and person is already four levels), and make your front end tolerate missing links, because an editor can unpublish a shared entry that published entries still point to.

Validations and appearance#

Validations are what make reuse safe. They stop editors publishing content that your front end, or another channel, cannot handle. The ones you will use most:

ValidationTypical use
RequiredFields a consumer cannot work without, such as a title or slug
UniqueSlugs, product codes and other identifiers (short text, integer and decimal number fields)
SizeMinimum and maximum length of text, or number of items in a list
Regular expressionFormats such as postcodes, phone numbers or internal codes
Predefined valuesA fixed set of options, shown to editors as a drop-down by default
Accepted typesWhich content types a reference may point to

Two details that catch teams out

  • Entries with an empty required field cannot be published, even if the field is hidden in the editor.
  • When you add a validation to an existing content type, existing entries are not checked until they are re-published. Content that breaks the new rule can stay live until someone edits it.

Appearance settings change how a field looks in the web app, not how it is delivered. Use them to choose the right editor for each field and to add help text, such as "Used on product cards and in search results", which tells editors a field is shared.

Localisation#

Contentful supports field-level localisation: you turn localisation on per field, and each localised field holds a value for every enabled locale within the same entry. Decide field by field:

FieldLocalise it?Why
Headlines, body copy, button labelsYesReaders see them in their own language
Image alt textYesScreen reader users hear it in their language
SlugsOnly if your URLs are translatedOtherwise one slug serves every locale
Internal codes, such as a SKUNoThey must match across locales and systems
Dates of a global eventNoThe event happens once, everywhere
References to entries that are themselves localisedNoThe linked entry already carries its own translations
Configuration flagsNoBehaviour should not change by language by accident

Every space has a default locale. When a localised field has no value for the requested locale, the API falls back to another locale. By default that is the default locale, but you can set custom chains, for example Mexican Spanish falling back to Spanish (Spain) and then to English. Setting a locale's fallback to null stops the chain. Note that fallback only applies when no value exists; a value deliberately set to an empty string through the API is returned as it is.

Assets can have locale versions too, just as entries can, which matters for images that contain text. Decide early whether images are shared or localised, because changing your mind later means revisiting every asset.

If markets need genuinely different content rather than translations, Contentful also documents entry-level localisation, where a container entry references a separate entry per locale.

Names and IDs#

Content type and field IDs are what your code reads, so treat them as permanent. Contentful generates a content type's ID from the name you type, which is convenient but can leave you with an ID based on a working title. Contentful's modelling basics guide treats a field's type and ID as fixed once created; the API reference describes a way to change a field ID but warns that doing so might break your existing code base.

Agree a naming convention before you create anything: singular nouns for content types, camelCase for field IDs, and no layout words such as "left", "hero" or "homepage".

Governance for shared entries#

Reuse cuts both ways. Contentful's documentation is explicit that edits to a referenced entry propagate to every entry that uses it, and are live everywhere once published. A well-meant edit to a shared disclaimer can change hundreds of pages. To manage that risk:

  • Restrict who can edit shared content types. Content permissions on custom roles can allow or deny actions by content type, field, tag and locale; Contentful states that custom roles are available on its Premium plan.
  • Use help text and naming to make shared content obvious to editors.
  • Before editing or unpublishing a shared entry, check which entries link to it.

Examples#

A reusable call-to-action. For example, a "Call to action" content type might have a short text label (required, with a size limit), a short text URL (required, with a pattern validation), and a "Style" field limited to predefined values such as "Primary" and "Secondary". Pages reference it through a many-references section field that accepts only approved section types, and articles embed it in rich text, with the rich text field restricted to embedding only this content type. The label is localised; the style is not. One edit to a campaign URL updates every page and article that uses it, which is also why editing rights for this type should be limited.

An author referenced by many articles. For example, a "Person" content type might hold a name, a role, a localised short bio and a headshot asset. Each "Article" has a single, required reference field that accepts only "Person" entries. Fetching an article with include=1 returns the author alongside it, so there is no need to go deeper. A correction to the bio appears on every article at once, and an unpublished author leaves a gap your front end must handle.

Primary sources#

[ Next step ]

Talk to us about your Contentful project

Tell us what you are building, changing or supporting. We’ll use the details to understand your requirements and arrange the next conversation.