Template languages: Velocity
GoLand lets you develop templates in Velocity (VTL) .
Coding assistance and syntax highlighting rely on the Apache Velocity plugin that you need to install and enable. For more information, refer to Install a plugin from Marketplace.
The following file types are supported by default:
VTL | .ft, .vm, .vsl |
To enable coding assistance for languages in which the static part of the template is written (those are referred to as template data languages), do one of the following:
Associate the template data language with files and folders in your project
In the Settings dialog (Ctrl+Alt+S) , click Languages and Frameworks and then click Template Data Languages.
Click the template data language cell to the right of the project or the corresponding directory or file, and select the language.
Click OK to apply changes.
Individual template files can be assigned a template data language directly in the editor using the Change template data language to context menu command.
Add an extension pattern for the corresponding file types
In the Settings dialog (Ctrl+Alt+S) , click Editor and then click File Types.
Under Recognized File Types, select Velocity Template.
Under File name patterns, click .
In the Add Wildcard dialog, specify the file name extension pattern, select a language, and click OK.
Click OK to apply changes.
Fixing unresolved references
GoLand provides inspections for detecting unresolved references in template languages:
Unresolved references can be fixed using intention actions. You can select to add a comment in the same file, or to create a separate file with comments. For more information, refer to Special comments.
In the latter case, a file with the default name velocity_implicit.vm
is created. This file starts with the following comment:
Code completion for defining reference types is available in the comments files.
If you rename the file or move it to a different location within the source root, reference definitions will not be lost.
Special comments
GoLand provides the following special comments for working with template languages:
Velocity comments are delimited using #*
and *#
.
Comment | Description |
---|---|
| Any Velocity file that starts with this comment is included in all files that are in the same module. Use such a dedicated comments file to define IDE-specific comments, so that they do not pollute your template files. |
| Defines a variable. For example, the following comment declares a variable named #* @vtlvariable name="foo" type="java.lang.String" file="path/to/file" *# To properly resolve |
| Defines the file with template macros relative to the file with this comment. For example, the following comment makes macros from #* @vtlmacrolibrary path="lib.vm" file="file.vm" *# |
| Defines the velocity.properties file and the runtime root directory relative to the file with this comment. For example: #* @velocityproperties path=”path/to/velocity.properties” runtime_root=”path/to/runtime/root/dir” *# |