Sitecore Content Serialization structural overview

Version: 10.2

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:

RequestResponse
{
  "$schema": "./.sitecore/schemas/RootConfigurationFile.schema.json",    
  "modules": [ "src/*/*.module.json" ]
}

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 can use the CLI and SVS to enable a watch command. This will monitor for changes in Sitecore and automatically pull serialized items to disk.

Including and excluding content items

You single out subsets of content items for serialization with includes and rules. This is useful for repeating the 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:

RequestResponse
"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:

RequestResponse
"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 descendants' 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.

Excluding fields in an SCS package

Note

The excluded fields feature is available from CLI 4.0 or later.

You can exclude fields from serialization by specifying them in the sitecore.json config file and any *modules.json file .

Note

Sync operations always ignore excluded fields. So if you change those fields in Sitecore, the CLI does not detect any changes, and pushing data does not override them. If you have excluded fields in YAML files, they are removed only after changes in the included fields or if you manually delete that exclusion and perform a pull operation.

The excludedFields property contains an array of the excluded fields with two properties: fieldId and description.

You can also configure excluded fields for the CLI commands package, watch, and diff.

Do you have some feedback for us?

If you have suggestions for improving this article,