Create Sitecore Ribbon Button using Sitecore PowerShell Extensions

Creating a custom Ribbon button in Sitecore using Sitecore PowerShell Extensions (SPE) involves several steps, which I'll guide you through below. The general process includes

  • Create PowerShell Script Module and Add Integration Point
  • Setup the PowerShell script Library and Add PowerShell script
  • Configuring the Ribbon button and Sync
  • Verify the button in the Ribbon

Here's how we can achieve that:

Pre-Requisites:

  • Running Sitecore Instance
  • PowerShell ISE to run PowerShell script

(Install compatible Sitecore.PowerShell.Extensions if it’s not there)

A close-up of a hand touching a field of grass

AI-generated content may be incorrect.

Step-1: Create PowerShell Script Module and Add Integration Point

  1. Create PowerShell Script Module:
    • Go to Content Editor.
    • In the content tree, navigate to: System > Modules > PowerShell > Script Library.
    • Right-click on Script Library and select Insert > PowerShell Script Module.

A screenshot of a computer

AI-generated content may be incorrect.

    • Give it a name, such as CustomScriptsModule and click OK

A screenshot of a computer

AI-generated content may be incorrect.

  1. Add Integration Point for Ribbon Button:
    • Right-click on the CustomScriptsModule we just created. We see different options here, lets select  

Insert > Integration Point Libraries.

              A screenshot of a computer

AI-generated content may be incorrect.

    • Here we see different Integration points, Select Content Editor > Ribbon > Proceed.

A screenshot of a computer

AI-generated content may be incorrect.

A screenshot of a computer

AI-generated content may be incorrect.

Now we will see the Item created under the CustomeScriptModule that we created in previous step.

Step-2: Setup the PowerShell script Library and Add PowerShell script

  1. Create PowerShell Script Library
    • Right-click on the Developer Ribbon in newly created item (under the module) and choose Insert > PowerShell Script Library.
    • Give any name like CustomeScriptLibrary

A screenshot of a computer

AI-generated content may be incorrect.

  1. Add PowerShell script
    • Right-click on the newly created PowerShell Script Library, and choose Insert > PowerShell Script.

A screenshot of a computer

AI-generated content may be incorrect.

    • Provide a meaningful name to the script, the same name command button will be added to the Ribbon

A screenshot of a computer

AI-generated content may be incorrect.

    • Elevate the session if required.

A screenshot of a computer

AI-generated content may be incorrect.

    • Provide the login password if asked.

A screenshot of a computer

AI-generated content may be incorrect.

    • Write the script: Now we can write PowerShell script that will be triggered by the Ribbon button. For instance, to show the item name when clicked, the script could look something like this:

# Get the current item

$item = Get-Item-Path .

# Show the item name in an alert

Show-Alert -Title $item.Name

A screenshot of a computer

AI-generated content may be incorrect.

Now we are done with the Script setup, its time to configure the Ribbon button.

Step-3: Configuring the Ribbon button

  1. Module Activation:
    • Go back to the module we created in previous step

/sitecore/system/Modules/PowerShell/Script Library/CustomeScriptModule

    • In the Module Activation section, click on the checkbox

Enabled – enables the module for all integration points

A screenshot of a computer

AI-generated content may be incorrect.

  1. Rebuild and Sync Library:
    • Open the PowerShell ISE (Integrated Scripting Environment) from the Sitecore Desktop.
    • Go to Settings and then Rebuild All
    • Select Sync Library with Content Editor Ribbon. This will sync the new button with the Ribbon UI in Sitecore. Once the processing is done, we can verify the new button.

A screenshot of a computer

AI-generated content may be incorrect.

  1. Configure Button Icon:
    • Click on the button (command - TestCommand)
    • CONFIGURE à Icon à set the icon

A screenshot of a computer

AI-generated content may be incorrect.

Step-4: Verify the button in the Ribbon

    • Go to Developer Ribbon and we can see the new button created

A screenshot of a computer

AI-generated content may be incorrect.

    • Click on this button will run the script we written. For this case it will return name of the selected item.

A screenshot of a computer

AI-generated content may be incorrect.

Example Use Cases:

While the above example shows how to display an item’s name when a button is clicked, we can also setup an interactive dialog that allows user input and adapt the PowerShell script to perform various tasks. Here are a few potential use cases:

  • Create a New Language Version of an Item: We can write a script to create a language version of an item by using PowerShell commands.
  • Delete Specific Language Versions: A script could delete items in specific languages by filtering by language and item path.
  • Fetch Data from an API and Save to Item: We can create a script that calls an external API and updates Sitecore items with the fetched data.

Benefits:

  • No C# Required: We can directly write PowerShell scripts without needing to setup any solution or write any C# code.
  • No Core Database Changes: This method allows us to create Ribbon buttons without manually modifying the Core database.
  • Flexible and Simple: The integration of Sitecore PowerShell Extensions provides a quick and simple way to add custom functionality to the Sitecore interface.

 

 

 

 

 

 

 

 

Comments

Popular posts from this blog

Setting Up Sitecore Headless with Next.js in Disconnected Mode

Step-by-Step Guide: Sitecore Headless GraphQL Filtering, Sorting & Pagination

Building a Headless Integration Between Sitecore and Azure Functions