Click here to view the official English-language source file JetBrains
Benpian Blog handling plus probably just translate it.
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.
Document template variables
Document templates can contain variables, after applying a template, these variables can be replaced by their values. A variable is a string that connected after the variable name begins with a dollar symbol "$." Variable name may be selected by braces "{}" enclosed. Such as: $ MyVariable and $ {MyVariable} variables are the same but different signs.
Predefined template variables
The following predefined variables can be used in file templates:
Variable | Description |
${DATE} | Current system date |
${DAY} | Current day of the month |
${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 file |
${HOUR} | Current hour |
${MINUTE} | Current minute |
${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) |
${ORGANIZATION_NAME} | Name of your organization specified in the project settings(Ctrl+Shift+Alt+S) |
${PRODUCT_NAME} | Name of the IDE(for example, PyCharm) |
${PROJECT_NAME} | Name of the current project |
${TIME} | Current system time |
${USER} | Login name of the current user |
${YEAR} | Current year |
Default template variables
The table to the predefined variables available in the document template:
variable | description |
${DATE} | The current system date |
${DAY} | The current day of a month |
${DS} | Dollar symbol $. This variable is used to escape the dollar character, so it will not be treated as the prefix template variables |
${FILE_NAME} | The name of the new file |
${HOUR} | Current hours |
${MINUTE} | Current minute |
${MONTH} | Current month |
${MONTH_NAME_FULL} | The full name of the current month (January, February, and so on) |
${MONTH_NAME_SHORT} | The first three letters of the name of the current month (Jan, Feb, and so on) |
${NAME} | The name of the new entity (document, classes, interfaces, and so on) |
${ORGANIZATION_NAME} | Specified in the project settings Name (Ctrl + Shift + Alt + S) |
${PRODUCT_NAME} | IDE name (eg: PyCharm) |
${PROJECT_NAME} | The current project name |
${TIME} | The current system time |
${USER} | The current user's login name |
${YEAR} | Current year |
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.
For example, if you want to use your full name instead of your login name defined through the predefined variable ${USER}
, use the following construct:
#set( $MyName = "John Smith" )
If the value of a variable is not defined in the template, PyCharm will ask you to specify it when the template is applied.
Custom template variables
除了预设定的模板变量,定制的变量也是可以的。必要的话,你可以在模板中使用#set指令
自定义一些变量的值。
举例,如果你想通过预设变量${USER}
用你的全名替代你的登录名,就使用下面的语法结构:
#set( $MyName = "John Smith" )
在模板中,如果变量的值没有定义的话,当模板应用后PyCharm会要求你进行设定。
下面我们用PyCharm看下实例