Wednesday, November 15, 2017

Create Custom Commands

Custom Command in 4 simple steps


  1. Create a class by inheriting (Sitecore.Shell.Framework.Commands.Command)
    • Implement Execute method --> Public override void Execute(CommandContext context) { SheerResponse.Alert("Hello from Custom Command"); }
    • Implement QueryState method (this method is optional based on the need) -->Public override CommandState QueryState(CommandContext context) { return context.Items[0].Children.Count == 0 ? CommandState.Hidden : base.QueryState(context); }
  2. Adding Following config tag in Commands.config located under (Sitecore/website/App_Config)
    • <command name=”item:[class name in all lower case letters]” type=”[fully qualified namesspace.classname, namespace]”/>
  3. Go to Sitecore Desktop and switch to “CORE” database
    • Select “Sitecore/Content/Applications/Content Editor/Context Menus/Default”
    • Create a new menu item
    • fill in the item fields --> Display name, Icon, Message = item:classname(id=$Target)
    • Save the changes and switch to “MASTER” database
  4. Right Click on any Sitecore item to notice newly added menu item

No comments:

Post a Comment

Setup Sitecore Serialization SCS

Are you looking to setup SCS on Sitecore 10.4 version in 5-10 minutes on your local Sitecore CM instance? then you have come to the right pl...