The context menu is designed to increase the efficiency of content authors. The requirements may vary for content authors across different organizations.
In this recipe, we will create a menu item in the context menu of a Sitecore item that will display the number of children that the selected item contains. In the same way, you will be able to create a command button for the Content Editor and Experience Editor ribbons as well.
We will first create a Command
class:
In the
SitecoreCookbook
project, create aGetChildCount
class in theCommands
folder. Inherit the class fromSitecore.Shell.Framework.Commands.Command
.Override the
Execute()
method of theCommand
class to apply a command action as follows:public override void Execute(CommandContext context) { if (context.Items.Length == 1) { Item currentItem = context.Items[0]; SheerResponse.Alert(string.Format("Children count: {0}", currentItem.Children.Count)); } }
Override...