eXtra-data schemas

Contents

eXtra-data schemas

X-data (short for eXtra data) makes it possible to dynamically extend existing content types with a new form. When editing content, X-data fields will be displayed inside a separate step in the content form.

If you want to inject fields inside content type’s form rather than appending a form, consider using a mixin

Definition

The file with X-data schema must be placed in the folder site/x-data/[name] and called [name].xml. For example, site/x-data/address/address.xml.

<x-data>
  <display-name>Full address</display-name>
  <form>
    <input type="TextLine" name="addressLine">
      <label>Street address</label>
      <occurrences minimum="0" maximum="2"/>
    </input>
    <input type="TextLine" name="city">
      <label>City</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextLine" name="zipCode">
      <label>Zip code</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextLine" name="country">
      <label>Country</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
  </form>
</x-data>

Usage

Below is an example of site.xml which injects X-data inside all content types.

<site>
  <form>
    <input type="TextLine" name="company">
      <label>Company</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextArea" name="description">
      <label>Description</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
  </form>
  <x-data name="address"/>
</site>

Configuration

It’s possible to restrict X-data for specific content types using regular expressions. This is especially convenient when you apply X-data to all content types via site.xml but want to exclude some content types.

Use regular expressions in the allowContentTypes attribute of the <x-data/> field inside site.xml to enable or disable it for specific content type(s). By default x-data will be added to content items of all types with no option to remove it but you can make it optional by setting optional attribute to true. Optional x-data has to be manually enabled inside Content Wizard to be added to the content data.

If allowContentTypes and optional attributes are not set, the x-data will automatically be enabled for all content types.

<site>
  <form>
    <input type="TextLine" name="company">
      <label>Company</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextArea" name="description">
      <label>Description</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
  </form>
  <x-data name="my-x-data-1" />
  <x-data name="my-x-data-2" allowContentTypes="^(?!base:folder$).*" />
  <x-data name="my-x-data-3" allowContentTypes="base:folder" optional="true" />
</site>

In the example above my-x-data-1 will be enabled for all content types, with no option to disable it in the Content Wizard.

my-x-data-2 will be added for all content types with no option to remove it in the Content Wizard, except for content type base:folder for which it will not be shown at all.

my-x-data-3 will be enabled only for content type base:folder and will be optional, meaning user has to manually turn it on in the Content Wizard.

Contents