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 template variables
The following predefined variables can be used in file templates:
Variable | Description |
---|---|
| Name of the package in which the new file is created if it's just regular file and package + '_test' suffix if the new file is a test file |
| Name of the package in which the new file is created |
| Current system date |
| Current day of the month |
| First three letters of the current month name (Mon, Tue, and so on) |
| Full name of the current day (Monday, Tuesday, and so on) |
| Path to the directory of the new file (relative to the project root) |
| Dollar sign |
| Name of the new file |
| Current hour |
| Current minute |
| Current second |
| Current month |
| Full name of the current month (January, February, and so on) |
| First three letters of the current month name (Jan, Feb, and so on) |
| Name of the new entity (file, %class%, interface, and so on) |
| Name of your organization specified in the project settings (Ctrl+Alt+Shift+S) |
| Name of the IDE (for example, GoLand) |
| Name of the current project |
| Current system time |
| Login name of the current user |
| 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. 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:
If the value of a variable is not defined in the template, GoLand will ask you to specify it when the template is applied.