1. Extending SXA

The SXA script library

Version:

SXA includes a number of PowerShell scripts to automate the most common tasks. The Sitecore PowerShell Extensions (SPE) module provides a command line and a scripting environment and enables you to use PowerShell from within Sitecore. In this way, you can run commands and write scripts according to Windows PowerShell syntax. Every SXA module that uses SPE has its own script library in: sitecore/System/Modules/PowerShell/Script Library/JSS SXA.

headless-site-spe-script-library.png
Note

PowerShell scripts can be used to automate tasks that you find yourself doing on a regular basis. To write your own scripts, or view code of existing scripts, use the PowerShell Integrated Scripting Environment (ISE). You can access this tool on the Sitecore Launchpad:

headless-site-launchpad-powershell-ise.png

The types of SXA scripts vary from cleanup scripts to cmdlts that add insert options to items:

  • Scaffolding – scripts used during scaffolding to automate the process of site/site collection creation.

  • Context Menu – scripts that are available for editors using the Content Editor. For example, the cleanup data sources script:

    49199728150943779499931A70CA2B68.png
  • Cmdlets – a lightweight command that is used in SPE and can be reused by other developers.

  • Insert Item – scripts that extend the Insert section in the Content Editor.

The following table describes the available SXA script modules, their functions, descriptions, and type of script:

ModuleFunctionDescriptionType of script
Basic SiteAdd Home RenderingsBuilds the basic content structure of the site.Scaffolding
MultisiteAdd Content fieldsDecorates new Site Collection templates with additional fields. Adds Content and Title fields to a Page template.Scaffolding
MultisiteSet home item title fieldSets the home item title after the site is created.Scaffolding
ScaffoldingAdd-JSSTenantContains all the functions used to create a new headless site collection.Cmdlets
ScaffoldingGet-AllJSSSiteGets all headlesss sites.Cmdlets
ScaffoldingGet-AllJSSTenantGets all headlesss site collections.Cmdlets
ScaffoldingGet-JSSSiteDefinitionGets headless site modules.Cmdlets
ScaffoldingGet-JSSTenantDefinitionGets headless site collection modules.Cmdlets
ScaffoldingInstall Headless Site moduleInstalls a headless site module.Cmdlets
ScaffoldingInstall Headless Site Collection moduleInstalls a headless site collection module.Cmdlets
ScaffoldingHeadless SiteAdds a script to the insert options in the context menu that lets users create a new headless site.Insert item
ScaffoldingHeadless Site CollectionAdds a script to the insert options in the context menu that lets users create a new headless site collection.Insert item
ScaffoldingNew-JSSTenantContains functions used to create a new headless site collection.Cmdlets
ScaffoldingNew-JSSSiteContains functions used to create a new headless site.Cmdlets
If you have suggestions for improving this article, let us know!