Previous: The Server Mode, Up: Customizing and Extending GPS

### 16.11 Adding project templates

The Project template wizard lists a selection of templates. The default set is found automatically by GPS in the `share/gps/templates` directory of your GPS installation.

It is possible to register new directories in which GPS will look for templates, by using the Shell/Python command `GPS.ProjectTemplate.add_templates_dir`.

To create a new project template, first create a subdirectory in the `share/gps/templates/` directory, or in one of the directories which has been registered through `GPS.ProjectTemplate.add_templates_dir`. Then, in this directory, create one template description file.

A template description file is a text file with the `.gpt` extension, with the following syntax:

         Name: <name>
         Category: <category>
         Project: <project file>
         <optional_hook_line>

         <variable_1>: <variable_1_default_value>: <variable_1_description>
         <variable_2>: <variable_2_default_value>: <variable_3_description>
         <etc>

         [Description]
         <the description>

Where the following should be defined:

- <name> The name of the template as it will appear in the template tree in the project template wizard.
- <category> The category in which the template will be inserted in the template tree. There can be multiple levels of categories, separated with `/`.
- <variable_1> A name which will be substituted in the template files when deploying the template, see below.
- <variable_1_default_value> The default value for variable 1, which will appear in the project template wizard.
- <variable_1_description> The description of variable 1.
- <optional_hook_line> An optional line of the form `post_hook: <python_file>` where `<python_file>` is the name of a Python file present in the same directory as the template description file. This Python file will be run by GPS once, right after the project template is deployed
- <description> A short paragraph describing the project template. This paragraph will be displayed in the project template wizard when the template is selected in the tree.

When deploying templates, GPS will copy in the destination directory chosen by the use all files and directories present in the directory that contains the template description file, except the Python file indicated as post_hook, and the template description file itself.

As it deploys templates, GPS will replace strings of the form `@_<variable_name>_@` with the value of the variable. If `<variable_name>` is all lower case, the substitution will be transformed to lower-case. If `<variable_name>` is in Mixed_Case, the substitution will be transformed into Mixed_Case as well. If it is in upper case, then the substitution will contain the original value specified by the user.