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.

The naming convention for these scripts is: SXA - Module name:

D0815973B19F47F4AD1979ACDBDF6FFD.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:

C6B1729442844F20A21E486CC0AA4A7B.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:

  • Module: Function
  • SXA – Compliancy: AddCookieWarning
  • SXA – Creative Exchange: ResolveCreativeExchangePathTokens
  • SXA – Forms: Set forms folder
  • SXA – Geospatial: Assign POI items
  • SXA – LocalDatasources: Cleanup Data Folder
  • SXA – Multisite: Add Content fields
  • Home base template: Adds a base template to the Home template under Site Collection templates. Adds a Page template as a base template.
  • Set home item title field: Sets the home item title after the site is created.
  • Set start item: Sets the start item on the site definition item. By default, the start item is a home item that is the root of all pages.
  • SXA – Search: Set default sorting facet
  • SXA – Site Metadata: AddBrowserTitle
  • AddCustomMetadata: Inserts the CustomMetadata rendering to metadata partial design.
  • AddFavicon: Inserts the Favicon rendering to metadata partial design.
  • AddOpenGraphMetadata: Inserts the OpenGraph rendering to metadata partial design.
  • AddSeoMetadata: Inserts the SeoMetadata rendering to metadata partial design.
  • AddStickyNotes: Inserts the StickyNotes rendering to metadata partial design.
  • AddTwitterMetadata: Inserts the TwitterMetadata rendering to metadata partial design.
  • AddViewport: Inserts the Viewport rendering to metadata partial design.
  • SXA – Scaffolding: MultisiteContext/Get-DataItem
  • MultisiteContext/Get-SettingsItem: The PowerShell wrapper for the IMultiSiteContext interface.Resolves the Settings folder for current site.
  • MultisiteContext/Get-SiteItem: The PowerShell wrapper for the IMultiSiteContext interface.Resolves the Site item for the current site.
  • MultisiteContext/Get-SiteMediaItem: The PowerShell wrapper for the IMultiSiteContext interface.Resolves the Virtual Media Library for the current site.
  • MultisiteContext/Get-TenantItem: The PowerShell wrapper for the IMultiSiteContext interface.Resolves the Site Collection item for the current site.
  • PresentationContext/Get-PageDesignsItem: The PowerShell wrapper for the IPresentationContext interface.Resolves the Page Designs folder for the current site.
  • PresentationContext/Get-PartialDesignsItem: The PowerShell wrapper for the IPresentationContext interface.Resolves the Partial Designs folder for the current site.
  • Add-BaseTemplate: Cmdlet that adds a base template.
  • Add-FolderStructure: Cmdlet that recreates the folder for a given path structure if it does not exist.
  • Add-InsertOptionsToItem: Cmdlet that adds InsertOptions (Masters) to an item.
  • Add-InsertOptionsToTemplate: Cmdlet that adds InsertOptions (Masters) to a Template item.
  • Get-PartialDesign: Returns the first Partial Design in the Partial Designs folder.
  • Test-ItemIsPartialDesign: Checks whether the item inherits from PartialDesignTemplate.
  • Test-ItemIsSiteDefinition: Checks whether the item inherits from SiteDefinitionTemplate.
  • New-Site: Contains all the functions used to create a new site.
  • New-Tenant: Contains all the functions used to create a new site collection.
  • Site: Adds script to the Insert options in a context menu that lets users create a new site. Appears when the following rules are met:

Rule 1
where the item template is SiteFolder
Rule 2
where the item template is Site Collection

  • Tenant: Adds script to the Insert options in a context menu that lets users create a new site collection. Appears when the following rules are met:

Rule 1
where the itemID is equal to Content
Rule 2
where the item template is Site Collection Folder

If you have suggestions for improving this article, let us know!