1. Development

Add modules to Site and Tenant scaffolding

Version:

Scaffolding lets you add modules to sites and tenants. SXA modules are stored in the Feature or Foundation folder:

  • /sitecore/System/Settings/Foundation/Experience Accelerator/
  • /sitecore/System/Settings/Feature/Experience Accelerator/

To define your new module, you must add the Site Setup, Tenant Setup, or Grid Setup item to the module and add action types from the Scaffolding folder (sitecore/Templates/Foundation/Experience Accelerator/Scaffolding/).

Add a module scaffolding definition

To add your own module scaffolding definition:

  1. Navigate to /sitecore/System/Settings/Foundation/ or /sitecore/System/Settings/Feature/ and add a folder.

  2. Right-click the new folder, and click Insert from template.

  3. In the Insert from template dialog box, navigate to sitecore/Templates/Foundation/Experience Accelerator/Scaffolding/Roots and, depending on the type of module that you want to add, click Grid Setup, Site Setup, or Tenant Setup, and then click Insert.

    Add new site setup.
  4. In the Data section, depending on the type of module that you want to install, fill in the following fields:

    SetupFieldDescriptions
    Site SetupNameThe name of the site module as you want it to display in the site creation wizard.
    DependenciesSpecify the order in which the modules are installed.
    Include by defaultSelect to enable the module by default in the site creation wizard.
    Include if installedDepending on whether the selected action was applied to the current tenant, the module will be automatically included.

    If the Selected field is empty, you can decide whether to install this module in the new-site creation wizard.
    Is system moduleSelect to install the module automatically. In this case, the module does not appear in the dialog box.
    Tenant SetupNameThe name of the tenant module as you want it to display in the tenant creation wizard.
    Include by defaultSelect to enable the module by default in the tenant creation wizard.
    Is system moduleSelect to install the module automatically. In this case, the module does not appear in the tenant creation wizard.
    Grid SetupNameThe name of the grid system as you want it to display in the site creation wizard.
    DependenciesSpecify the order in which the modules are installed.
    Grid DefinitionRefers to the Grid Definition item. For example, for the Foundation grid system: Settings/Feature/Experience Accelerator/Foundation/Foundation

Add scaffolding actions

You can use various action types to define modules. You can add items, edit the template, and execute PowerShell scripts. The available actions are stored in the Actions folder (sitecore/Templates/Foundation/Experience Accelerator/Scaffolding/Actions):

Scaffolding actions

To add a scaffolding action:

  • Navigate to your new module and right-click the setup item that you added for your new module. For example, right-click the Site Setup item and insert the Add Site Item action.

    Add Site item

The following actions are available:

Action typeFieldDescription
Add Tenant ItemLocationAdds the new item under the tenant.
TemplateTemplate used to create the new tenant item.
NameName of the item.
FieldsField/value mapping to set the fields of the new item after creation.
Edit Tenant TemplateTemplateSelect the template to copy into tenant templates. The template is edited according to the defined settings.
Type of actionSelect the action type.
Base templates or insert options templatesSelect items to use as an argument for the action selected in the previous field.
Execute Tenant ScriptScriptSelect the PowerShell script to execute. You can use scaffolding scripts to automate parts of the site/tenant creation process. For example:

csharp<br>function Invoke-ModuleScriptBody {<br>[CmdletBinding()]<br> param(<br> # Depending on context could be a Tenant or Site item<br> [Parameter(Mandatory=$true, Position=0 )]<br>[Item]$Root,<br>[Parameter(Mandatory=$true, Position=1 )] <br> [Item[]]$TenantTemplates <br> )<br>begin {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - Begin"<br>}<br>process {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - Process"<br> # Script body<br> # Put your custom logic here<br>}<br>end {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - End"<br>}<br>}<br>
Add Site ItemLocationAdds the new item under the site.
TemplateTemplate used to create a new site item.
NameName of the new site item.
FieldsField/value mapping to set the fields of the new item after creation.
Edit Site ItemTemplateEdits Site items by adding additional insert options.
Type of actionSelect the action type.
Insert optionsDefine the insert options for the item.
Execute Site ScriptScriptSelect the PowerShell script to execute. You can use scaffolding scripts to automate parts of the site/tenant creation process. For example:

csharp<br>function Invoke-ModuleScriptBody {<br>[CmdletBinding()]<br> param(<br> # Depending on context could be a Tenant or Site item<br> [Parameter(Mandatory=$true, Position=0 )]<br>[Item]$Root,<br>[Parameter(Mandatory=$true, Position=1 )] <br> [Item[]]$TenantTemplates <br> )<br>begin {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - Begin"<br>}<br>process {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - Process"<br> # Script body<br> # Put your custom logic here<br>}<br>end {<br>Write-Verbose "Cmdlet Invoke-ModuleScriptBody - End"<br>}<br>}<br>
Edit Editing ThemeBase ThemesList of base themes to add to an editing theme instance.
Edit Site ThemeBase ThemesList of base themes to add to an editing theme instance.
Post Setup StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to execute actions once the site is created.

csharp<br>function Invoke-Step {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Sitecore.XA.Foundation.Scaffolding.Models.CreateNewSiteModel]$Model<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process"<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>}<br>
Input Validation StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to validate the model before the site is created. If the result returned by any of validation scripts is false, the New Site dialog box will display again so that you can correct some of the previously selected values.

csharp<br>function Invoke-Validation {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Sitecore.XA.Foundation.Scaffolding.Models.CreateNewSiteModel]$Model<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process" <br> # Return $true or $false as a result of validation<br> $true<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>
Post Setup StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to execute actions once tenant is created.

csharp<br>function Invoke-Step {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Sitecore.XA.Foundation.Scaffolding.Models.CreateNewTenantModel]$Model<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process"<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>}<br>
Input Validation StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to validate model before the tenant is created. If the result returned by any of validation scripts is false, the New Tenant dialog box will display again so that you can correct some of the previously selected values.

csharp<br>function Invoke-Validation {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Sitecore.XA.Foundation.Scaffolding.Models.CreateNewTenantModel]$Model<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process"<br> # Return $true or $false as a result of validation<br> $true<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>}<br>
Pre Delete StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to automate parts of the site/tenant removal process. This action will be executed when Remove-Tenant or Remove-Site cmdlet are invoked. You can use it to clean-up items created by custom modules because they are not removed by default removal processes (for example because the items are in different folders)

csharp<br>function Invoke-Step {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Item]$Root<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process"<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>}<br>
Post Delete StepScriptSelect the PowerShell script to execute. You can use scaffolding scripts to automate parts of the site/tenant removal process. This action will be executed when someone will invoke Remove-Tenant or Remove-Site cmdlet. You can use this to cleanup your items created by custom modules that would not be removed during standard removal (for example, if you stored items outside well-known folders such as tenant/site root item, tenant/site media library, tenant templates)

csharp<br>function Invoke-Step {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Item]$Root<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-PostDeleteStep - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-PostDeleteStep - Process"<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-PostDeleteStep - End"<br> }<br>}<br>
Pre Delete Validation StepSelect the PowerShell script to execute. You can use scaffolding scripts to automate parts of the site/tenant removal process.

You can use scaffolding scripts to validate state before removing the tenant or site. If the result returned by any of validation scripts is false, the Delete operation will be canceled.

csharp<br>function Invoke-Validation {<br> [CmdletBinding()]<br> param(<br> [Parameter(Mandatory = $true, Position = 0 )]<br> [Item]$Root<br> )<br> begin {<br> Write-Verbose "Cmdlet Invoke-Validation - Begin"<br> }<br> process {<br> Write-Verbose "Cmdlet Invoke-Validation - Process"<br> # Return $true or $false as a result of validation<br> $true<br> }<br> end {<br> Write-Verbose "Cmdlet Invoke-Validation - End"<br> }<br>}<br>
If you have suggestions for improving this article, let us know!