Creating and Editing File Templates
Creating a file template from scratch
- Open Settings/Preferences dialog and under the Editor node, select File and Code Templates page.
- Switch to the Files tab.
- Click on the toolbar and specify the template name, file extension, and the body of the template, which can contain:
- Plain text.
#parse
directives to work with includes.- Predefined variables to be expanded into corresponding values in the format
${<variable_name>}
.The available predefined file template variables are:
-
${PROJECT_NAME}
- the name of the current project. -
${FILE_NAME}
- the name of the PHP file that will be created. -
${NAME}
- the name of the new file which you specify in the New File dialog box during the file creation. -
${DATE}
- the current system date. -
${TIME}
- the current system time. -
${YEAR}
- the current year. -
${MONTH}
- the current month. -
${DAY}
- the current day of the month. -
${HOUR}
- the current hour. -
${MINUTE}
- the current minute. -
${PRODUCT_NAME}
- the name of the IDE in which the file will be created. -
${MONTH_NAME_SHORT}
- the first 3 letters of the month name. Example: Jan, Feb, etc. -
${MONTH_NAME_FULL}
- full name of a month. Example: January, February, etc. $USER_NAME
- for macOS users: the registered full name of the user; for Linux and Windows users: the login name of the current user.$HEADER_FILENAME
- the name of a header file, generated for a class or a source file.$HEADER_COMMENTS
- always returnstrue
and is used for testing purposes.$NAMESPACE_OPEN
- indicates the beginning of a namespace block created during refactoring.$NAMESPACE_CLOSE
- indicates the end of a namespace block created during refactoring.$INCLUDE_GUARD
- prevents from repeated include of the particular header file.$RETURN_TYPE
- the type of a function return value and is used for a new functions generation.$DEFAULT_RETURN_VALUE
- specifies the default function's return value.$CALL_SUPER
- returns the base function call signature during the override generation.$SUIT_NAME
- specifies the Google test suite name.$TEST_NAME
- specifies the Google test name.$END
- indicates the caret position upon finishing the variables editing.
-
- Custom variables. Their names can be defined right in the template through the
#set
directive or will be defined during the file creation.
- To have the dollar character (
$
) in a variable rendered "as is", use the${DS}
variable instead. This variable evaluates to a plain dollar character ($
). - Apply the changes and close the dialog box.
Creating a file template from an existing one
- Open the File Templates settings page and switch to the Files tab.
- Click on the toolbar and change the template name, extension, and source code as required.
- Apply the changes and close the dialog box.
Creating a file template from a file
- Open the desired file in the editor.
- On the main menu, choose .
- In the File and Code Templates dialog box that opens specify the new template name and edit the source code, if necessary.
- Apply the changes and close the dialog box.
Creating and referencing include templates
Include templates are used to define reusable pieces of code to be inserted in file templates through #parse
directives.
To create and reference an include templates
- In the File and Code Templates settings page, switch to the Includes tab.
- Click on the toolbar and specify the template name, extension, and the source code. Do one of the following:
- Use the predefined file template variables.
- Create custom template variables and define their values right in the include template using the
#set
VTL directive.
For example, if you want to your full name inserted in the file header instead of your login name defined through the${USER}
, write the following construct:If, when applying a template, the values of certain template variable are not known, CLion will ask you to specify them.#set( $MyName = "John Smith" )
$
) in template variables as prefixes. If you need a dollar character ($
inserted as is, use the${DS}
file template variable instead. When the template is applied, this variable evaluates to a plain dollar character ($
). - To use the include template, switch to the Templates tab, select the desired template and click Edit.
- To include a template, insert the #parse directive in the source code.
Last modified: 15 December 2017