Mixin schemas

Contents

Mixin schemas

If you need to repeat a group of fields in several different content types, consider extracting them into a mixin. After that you can add a reference to the mixin inside forms of required content types.

If you want to append a separate form of fields rather than injecting fields inside content type’s form, consider using X-data

Definition

The file with mixin schema must be placed in the folder site/mixins/[name] and called [name].xml. For example, site/mixins/address/address.xml.

<mixin>
  <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>
</mixin>

Usage

Below is an example of a simple content type that uses the abovementioned address mixin. In this case fields defined in the mixin will be injected after the form fields of the content type schema, and their values will be saved with content data. Notice that the name of the mixin file is used and not the mixin’s Display Name.

<content-type>
  <display-name>Using mixins</display-name>
  <form>
    <input type="TextLine" name="firstName">
      <label>First Name</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <input type="TextLine" name="lastName">
      <label>Last Name</label>
      <occurrences minimum="1" maximum="1"/>
    </input>
    <mixin name="address"/>
  </form>
</content-type>
Mixins can be used in content types, component descriptors and the site.xml file.

Contents