Sitecore Content Serialization structural overview

Abstract

Overview of the Sitecore Content Serialization (SCS) structures.

You serialize content items in and out of a Sitecore instance using the Sitecore Content Serialization (SCS) system. This is done by configuring which content items to include and which ones to exclude, and which operations to perform on the content items.

The SCS system serializes content items into your project folder as YAML files. The default path is \serialization relative to the module file, but you can configure the relative serialization path to any path you want.

The project configuration file

The project configuration file is named sitecore.json. It has several properties including a modules property that references the relevant Sitecore Content Serialization modules.

A project configuration in its simplest form looks like this:

{
  "$schema": "./.sitecore/schemas/RootConfigurationFile.schema.json",    
  "modules": [ "src/*/*.module.json" ],
  "variables": {},
    "serialization": {
      "defaultMaxRelativeItemPathLength": 120,
      "defaultModuleRelativeSerializationPath": "serialization"
   }
}

Manual and automatic serialization

You can serialize manually or automatically:

  • You use manual serialization when you want to push or pull content items to or from a Sitecore instance on demand.

  • You use automatic serialization to specify content items that you would like to have automatically serialized from a Sitecore instance to your file system when they are created or updated.

Including and excluding content items

You single out subsets of content items for serialization with includes and rules. This is useful for repeating serialization of particular parts of your content item tree.

You configure what and how content items are included and excluded from serialization in a module file such as Project.module.json. You can place and override serialization configurations in all module files.

Note

A content item is only included once across all modules.

Each include must have a name property that becomes a folder name in your file system and a path property that specifies what part of your content item tree to serialize.

For example, to serialize your entire content item tree to the serialization\content\ folder in your file system, add this to your Project.module.json file and run the sitecore ser pull command:

"items": {
  "includes": [
    {
      "name": "content",
      "path": "/sitecore/content/home"
    }
  ]
}

Important

The order of the includes is important. If your content items are dependent on a template in the same module, your template include must come first.

See the Sitecore Content Serialization configuration reference for the complete list of include and rule properties.

Note

Include properties are referred to as root properties, as in root name and root path.

Rules

Rules are used to configure the serialization of content item trees. You configure rules with a path relative to the root path, the scope of content items to influence, and any alterations to the allowed push operations.

For example, if you want to synchronize the /sitecore/content/home/products/ path and all its descendants except those in the legacy/ path, you add an include like the following:

"items": {
  "includes": [
    {
      "name": "content",
      "path": "/sitecore/content/home",
      "rules": [
        {
           "path": "/products/legacy",
           "scope": "ignored"
        },
        {
           "path": "/products",
           "scope": "ItemAndDescendants",
           "allowedPushOperations": "createUpdateAndDelete"
        },
        {
           "path": "*",
           "scope": "ignored"
        }
      ]
    }
  ]
}

The rule system works by the first-match-wins principle, meaning that when a content item matches a rule, all subsequent rules are ignored:

  • The first rule tells SCS to ignore all content items in the /sitecore/content/home/products/legacy path.

  • The second rule tells SCS to serialize all content items in the /sitecore/content/home/products path. All subcontent items are included because the scope is ItemAndDescendants.

  • The third rule prevents SCS from serializing any more /sitecore/content/home content items. The wildcard path of this rule matches all content items not matched by the previous rules, and the ignored scope prevents them from being serialized.

Keep the following things in mind when you configure rules:

  • Do not let rule paths overlap. Or, if you do, you must put the most specific rule first.

  • Rules for parent's paths override rules for children's and descendant's paths.

  • Rule scopes cannot be more inclusive than the root scope. For example, if the root scope is ItemAndChildren, the rule scope cannot be ItemAndDescendants.

  • The alias property in a rule replaces the root name property (the folder name in your file system) for this particular rule.

  • If you have configured an alias property and a scope property with an ignored value, the scope is used. Content items scoped to be ignored are not influenced by aliases.

See the Sitecore Content Serialization configuration reference for all configurable rule properties.