Thursday, June 29, 2006

Creating Debug Item button


You may consider adding a button to the Content Editor’s toolbar and context menu that will start the debugging of the selected item. Here are the steps: 1. Create a new command named Debug under /Content/System/Commands in the core database. 2. Fill all necessary fields in the newly created command. Pay attention to the following ones: • Click – you can set some arbitrary value here, for example item:debug. • Type – specify namespace.class_name,assembly_name here of the class which is shown below: using System; using Sitecore; using Sitecore.Data.Items; namespace Sitecore.Shell.Commands { public class DebugItem : CommandBase { public override bool Execute(Item[] itemArray) { Context.ClientPage.ClientResponse.Eval("window.open('/?sc_itemid=" + itemArray[0].ID.ToString() + "&sc_debug=1', '_blank')"); return true; } public override CommandStatus QueryStatus(Item[] itemArray2) { return CommandStatus.Normal; } } } As can be seen, we inherited this class from the CommandBase class. The key method is named Execute where we are opening the selected item in debug mode in new window. The QueryStatus method is obligatory to be overridden. 3. Navigate to System/Shell/__Default/Commands and Add “Debug” to the Commands multilist field That’s all, the command should be present in the context menu. After clicking, you should get the selected item in the debug mode. Note that the selected item should be present in the web database, otherwise, the home node will be shown upon clicking on the Debug command.

0 comments: