Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: DOCU-2700

...

clearboth
width343px
alignright
classmenu

This page provides an overview of all ways to define custom JCR node types and create new workspaces with Magnolia.

...

Table of Contents
maxLevel3
minLevel2

With content types

...

By utilizing the magnolia-content-types module you can define custom JCR content types and workspaces within light modules.

...

  1. JCR workspace
  2. JCR nodetype
    This node type inherits from the Magnolia node type mgnl:content. To define more sophisticated node types, you can create a node type definition file in a light module
  3. JCR namespace

Example

bitbucket-cmeier-repogitcmsuserscmeier/repos/content-type-examples/raw/contentTypes/tourGuide.yaml?at=master
Code Pro
profile
languageyml
sections%%datasource%% - %%shortBio%%
url
datasource:
  workspace: tourguides
  namespaces:
    mt: https://
www.magnolia-
travel.com/
jcr/
1.0/mt
  autoCreate: true
  
model:
  nodeType: mt:tourGuide
  properties:
    - name: birthday
      type: Date
    - name: gender
    - name: shortBio
Bestpractice

If a node type inheriting from mgnl:content complies with your requirements, we recommend defining all of the items – namespace, node type and workspace in the content type definition, all in one file.

...

  1. Create an XML-based node type definition file in your light module:

    bitbucket-cmeier-repogitcmsusers/cmeier/repos/content-type-examples/raw/jcr-node-type-files/travellers-node-types.xml?at=master
    Code Pro
    profile
    languagexml
    title/content-type-examples/jcr-node-type-files/travellers-node-types.xmlurl
    <nodeTypes
        xmlns:mgnl="http://www.magnolia.info/jcr/mgnl"
        xmlns:mt="https://
    www.magnolia-
    travel.com/
    jcr/1.0/mt">
      <nodeType name="mt:traveller" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
        <supertypes>
          <supertype>mgnl:content</supertype>
        </supertypes>
      </nodeType>
      <nodeType name="mt:tourGuide" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
        <supertypes>
          <supertype>mt:traveller</supertype>
        </supertypes>
      </nodeType>
      <nodeType name="mt:happyCustomer" isMixin="false" hasOrderableChildNodes="true" primaryItemName="">
        <supertypes>
          <supertype>mt:traveller</supertype>
        </supertypes>
      </nodeType>
    </nodeTypes>
  2. Reference the node type definition from a content type definition:

    raw/contentTypes/happyCustomer.yaml?at=master
    Code Pro
    https://git.magnolia-cms.com/users/cmeier/repos/
    profilebitbucket-cmeier-repo
    languageyml
    title/content-type-examples/contentTypes/happyCustomer.yaml
    linenumberstrueurl
    datasource:
      workspace: happycustomers
      autoCreate: true
      nodeTypeDefinition: /content-type-examples/
    jcr-node-type-files/travellers-node-types.xml
     
    model:
      nodeType: mt:happyCustomer
      properties:
        - name: country
        - name: age
          type: Double

    Line 4: References the node type definition resource via nodeTypeDefinition.

...