---
title: "Create a command template"
slug: "create-a-command-template"
abstract: "How to create a command template."
---
# Create a command template

[Command templates](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-manager/command-templates.html "Command templates") initiate commands to create one or more items programmatically.

To create a command template:

1. Create a class that inherits from `Sitecore.Shell.Framework.Commands.Command`, and override the `Execute()` method as illustrated in the following code sample:

    ```csharp
    namespace Namespace.Shell.Framework.Commands
     {
         public class ClassName : Sitecore.Shell.Framework.Commands.Command
         {
             public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
            {
            }
         }
    }
    ```

2. Add a `/configuration/command` element to the `/App_Config/Commands.config` file, mapping the command code in the name attribute to the class signature in the type attribute. For example:

    ```text
    <command name="namespace:category:command" type="Namespace.Shell.Framework.Commands.ClassName,Assembly" />
    ```

3. In the Template Manager or the Content Editor, within */Sitecore/Templates*, insert any required project-specific folders using the /*Templates/Common/Folder* data template.
4. Under the relevant project-specific folder within */Sitecore/Templates*, insert a command template definition item using the `/System/Branches/Command Template data template`.
5. In the command template definition item, in the **Data** section, for the **Command** field, enter the command code. For example:

    ```text
    namespace:category:command(id=$ParentID)
    ```

    The parameter `id=$ParentID` sets the ID passed to the command to the item under which the user is inserting a new item. This causes Sitecore to pass the correct item ID to the command template when the user has selected an item, but has right-clicked another item before activating the command template. Without this parameter, Sitecore would pass the ID of the selected item rather than the item that the user right-clicked.

> [!note]
> You can [assign or copy insert options](https://doc.sitecore.com/xp/en/developers/102/sitecore-experience-manager/assign-or-copy-insert-options.html "Assign or copy insert options") to other items to allow the use of the new command template.