CLion 2024.1 Help

File template variables

A file template can contain variables, which are replaced by their values when the template is applied. A variable is a string that starts with a dollar sign $ followed by the variable name. The variable name may optionally be enclosed in curly braces. For example: $MyVariable and ${MyVariable} are different notations of the same variable.

Predefined and custom variables are available in the template body and in the filename. For example, if you type MyFile_${MONTH_NAME_FULL} in the File name field of your template, the resulting file will be named MyFile_April if you create it in April. Here, ${MONTH_NAME_FULL} is a predefined variable. If you use a custom variable instead, CLion will prompt you to enter the variable value when you create a file based on this template.

Variable in a file template

Predefined template variables

The following predefined variables can be used in file templates:

Variable

Description

${CALL_SUPER}

Base function call signature during the override generation

${DATE}

Current system date

${DAY}

Current day of the month

${DEFAULT_RETURN_VALUE}

Default return value of the function

${DIR_PATH}

Path to the directory of the new file (relative to the project root)

${DS}

Dollar sign $. This variable is used to escape the dollar character, so that it is not treated as a prefix of a template variable.

${FILE_NAME}

Name of the new C or C++ file

${HEADER_COMMENTS}

Always returns true and is used for testing purposes

${HEADER_FILENAME}

Name of the header file generated for a class or a source file

${HOUR}

Current hour

${INCLUDE_GUARD}

Prevents repeated include of a particular header file

${MINUTE}

Current minute

${SECOND}

Current second

${MONTH}

Current month

${MONTH_NAME_FULL}

Full name of the current month (January, February, and so on)

${MONTH_NAME_SHORT}

First three letters of the current month name (Jan, Feb, and so on)

${NAME}

Name of the new entity (file, class, interface, and so on)

${NAMESPACE_CLOSE}

End of a namespace block created during refactoring

${NAMESPACE_OPEN}

Beginning of a namespace block created during refactoring

${PRODUCT_NAME}

Name of the IDE (for example, CLion)

${PROJECT_NAME}

Name of the current project

${RETURN_TYPE}

Type of the function's return value (used for generating new functions)

${SUIT_NAME}

Google test suite name

${TEST_NAME}

Google test name

${TIME}

Current system time

${USER}

Login name of the current user (all platforms)

${USER_NAME}

For Windows and Linux: login name of the current user

For macOS: registered full name of the user

${YEAR}

Current year

The following variables are available in CMakeLists.txt file templates:

${CMAKE_DEFAULT_PROJECT_FILE}

the main.cpp/main.c/libary.cpp/library.c file of the project.

${CMAKE_LANGUAGE_VERSION}

the selected language standard.

${CMAKE_MAJOR_VERSION}

the major number of the minimum supported CMake version. For example, if the version if 3.20, this variable corresponds to 3.

${CMAKE_MINOR_VERSION}

the minor number of the minimum supported CMake version. For example, if the version if 3.20, this variable corresponds to 20.

${CMAKE_LIBRARY_TYPE}

SHARED for shared libraries.

${QT_VERSION}

the selected Qt version.

${REQUIRED_LIBS}

the Qt libraries required for the selected project type. By default, they are Core for Qt Console Executable and Core, Gui, Widgets for Qt Widgets Executable.

Variable methods

Because CLion uses Velocity as a template engine for file templates, variables in file templates can use Java String methods. For example, the following is possible:

  • ${NAME.toUpperCase()}: convert the name of the new entity (file) to upper case letters.

  • ${PROJECT_NAME.length()}: print the length of the project name.

  • ${PRODUCT_NAME.substring(0,5)}: print the first five characters of the name of the IDE you are using.

Custom template variables

Besides predefined template variables, it is possible to specify custom variables. If necessary, you can define the values of custom variables right in the template using the #set directive. Write the directive before the corresponding variable is used.

For example, if you want to use your full name instead of your login name defined through the predefined variable ${USER}, add the following construct before your custom variable:

#set( $MyName = "John Smith" )

If the value of a variable is not defined in the template, CLion will ask you to specify it when the template is applied.

Last modified: 26 May 2024