Command templates
A command template (also known as a command template definition item) defines a class and method to be called during an insert operation. You can create a command template that does not display a user interface, a command template that uses a JavaScript prompt to collect an item name, or a command template that displays an ASP.NET user interface. Command templates typically invoke a wizard application that collects information from a user and then programmatically creates an appropriate set of items.
A command template can be assigned as an insert option to items and standard values. The command template insert option appears identical to data template and branch template insert options. The only difference is that the command template insert option triggers a Sitecore UI command. You can assign command templates along with data templates and branch templates using insert options.
For example, you can use a command template to invoke a wizard that gathers information from the user before creating items. Unlike data templates and branch templates, which consist of predefined structures, command templates reference Sitecore UI commands to invoke wizards or other logic used to create new items.
In the following image, you can see the Language command template that is used when you create new languages. In the right-hand pane, you can see the Command field which contains the name (system:addlanguage in this case) of the command that is called when the command template is invoked.
One example of a Sitecore defined command template involves creating a template:
-
The insert options for /Sitecore/System/Languages include the /Sitecore/Templates/Branches/System/Globalization/Language command template.
-
This invokes the same command used by the control panel to create a new language.
-
The value of the Command field in each command template corresponds to an entry in the
/App_Config/Commands.config
file and makes the system invoke methods in the specified class when the user invokes the command template.