5

I would like to have a custom context menu like the following:

Hello Menu

Since this menu item does not follow the typical integration points for SPE, how would I go about making it work with a script?

1
  • Thanks Michael, This is very useful, wonder if we can pass dynamic values to the script from the context Menu? Thanks in Advance.
    – user2475
    Commented Jul 6, 2023 at 17:23

1 Answer 1

9

The first step would be to create a custom script in one of your modules.

For example, create a custom SPE module using the wizard followed by whatever library structure you prefer. Check out the official SPE docs for additional details.

Module

Show-Alert -Title "Hello!"
Close-Window # Causes the runner dialog to close automatically

Copy the item ID of the script.

Switch to the core database and create a new menu item. For the demo we'll create it at the following path:

# Item path
/sitecore/content/Applications/Content Editor/Context Menues/Default/Say Hello

Menu item

The Message field should contain the following where the script parameter matches the item ID of the script.

item:executescript(id=$Target,script={5BCE1B7C-E484-4809-B34F-C1F2B65905DD}, scriptDb=master)

Switch back to the master database and give the new menu item a try.

Message

Note: Big thanks to Kurt Bilde for asking about it on Sitecore Chat.

1
  • This works - thanks for sharing this one!!!
    – Kurt Bilde
    Commented Jul 5, 2023 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.