Content type definition

Use the Magnolia Content type definition to specify a content type.

A Magnolia content type is a formal definition for a type of content in Magnolia including the properties the type may contain and its relationships to other types of content. A content type is configured in a content type definition that includes the data source definition and model definition.

Content type items can be managed by a content app. The content can be embedded into web pages or served via REST in a headless approach.

The base interfaces for content type definition are agnostic of data source type.

However, the Magnolia Content Types module provides also specific definition classes for JCR data to define custom JCR workspaces, node types, and namespaces.

The definition item can be supplied via any Magnolia Resource origin. You can create them in a light module, in a Magnolia Maven module or in the JCR configuration workspace (see Location of content type definitions). New content type definition items are detected by the magnolia-content-types module and registered in info.magnolia.types.ContentTypeRegistry using the name of the definition as the ID.

Properties

/content-type-examples/contentTypes/tourGuide.yaml
datasource: (1)
  $type: jcrContentTypeDatasource
  workspace: tourguides
  namespaces:
    mt: https://www.magnolia-travel.com/jcr/1.0/mt
  autoCreate: true

model: (2)
  nodeType: mt:tourGuide
  properties: (3)
    - name: birthday
      type: Date
    - name: gender
    - name: shortBio
1 datasource required Defines the data source.
2 model required Defines the model of the content type.
3 name optional The value of the name property under properties is automatically assigned by the name of the resource which defines the content type (YAML file name without the suffix or JCR node name). Set the property in the content definition to override the automatically assigned value.

Content type property suffixes

When you define a content type property, you should avoid using a 2-letter suffix. This is because Magnolia reads the suffix as a language such as property_en or property_de.

If you add a 2-letter suffix, the property is not delivered when using the Delivery API.
Example
datasource:
  $type: jcrContentTypeDatasource
  workspace: tourguides
  namespaces:
    mt: https://www.magnolia-travel.com/jcr/1.0/mt
  autoCreate: true

model:
  nodeType: mt:tourGuide
  properties:
    - name: description (1)
      type: String
      i18n: true
...
    - name: description_ins (2)
      type: String
      i18n: true
...
    - name: description_in (3)
      type: String
      i18n: true
1 A correct property name with no suffix.
2 A correct property name with an acceptable suffix.
3 An incorrect property name with the 2-letter suffix.

Location of content type definitions

The definition item can be supplied via any Magnolia Resource origin.

You can create them:

  • in a light module

  • in a Magnolia Maven module

  • in the JCR configuration workspace.

Content type name

When creating content types, use singular and countable forms like

  • book

  • photograph

Otherwise, Magnolia GraphQL types will have double plural forms like bookses and photographses.

App name

Append -app to the name of the app, for example:

  • books-app

  • photographs-app

Workspace name

If possible, use the plural form, for example:

  • books

  • photographs

Light module

Add the configuration to the /<module-name>/contentTypes folder.

my-light-module/
└── contentTypes
    └── my-content-type.yaml (1)
1 Name of the definition: my-content-type

Magnolia Maven module

Add the configuration to the resources/<module-name>/contentTypes folder.

my-maven-module/
└── src
    └── main
        └── resources
            └── my-maven-module
                └── contentTypes
                    └── larrys-content-type.yaml (1)
1 Name of the definition: larrys-content-type

JCR configuration workspace

Add the configuration to the /modules/<module-name>/contentTypes folder.

JCR configuration workspace

Name of the definition: boat-content-type

Interface and class

The base interface for a content type definition is info.magnolia.types.ContentTypeDefinition. The base implementation class is info.magnolia.types.ConfiguredContentTypeDefinition.

Feedback

DX Core

×

Location

This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules