# Template languages: Velocity and FreeMarker

IntelliJ IDEA lets you develop templates in [Velocity](https://velocity.apache.org) (VTL) and [FreeMarker](https://freemarker.apache.org/) (FTL).

Coding assistance relies on the Apache Velocity and FreeMarker plugins which are bundled and enabled in IntelliJ IDEA with the Ultimate subscription by default. If the relevant features aren't available, make sure that you didn't disable the plugin. For more information, refer to [Open plugin settings](managing-plugins.html#open-plugin-settings).

![Template language directives completion](https://resources.jetbrains.com.cn/help/img/idea/2026.2/velocity_code_completion_1.png)

![Template language variables completion](https://resources.jetbrains.com.cn/help/img/idea/2026.2/velocity_code_completion_2.png)

The following file types are supported by default:

| VTL | `.ft`, `.vm`, `.vsl` |
| FTL | `.ftl`, `.ftlh`, `.ftlx` |

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:

Procedure: Associate the template data language with files and folders in your project

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), click Languages and Frameworks and then click Template Data Languages.

2. Click the template data language cell to the right of the project or the corresponding directory or file, and select the language.

3. 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.

Procedure: Add an extension pattern for the corresponding file types

1. In the Settings dialog (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))), click Editor and then click File Types.

2. Under Recognized File Types, select FreeMarker Template or Velocity Template.

3. Under File name patterns, click ![](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.general.add.svg).

4. In the Add Wildcard dialog, specify the file name extension pattern, select a language, and click OK.

![velocity_add_pattern](https://resources.jetbrains.com.cn/help/img/idea/2026.2/velocity_add_pattern.png)

5. Click OK to apply changes.

## Fixing unresolved references

IntelliJ IDEA provides [inspections](code-inspection.html) for detecting unresolved references in template languages:

![Example template language inspection for unresolved references](https://resources.jetbrains.com.cn/help/img/idea/2026.2/velocity_inspection.png)

Unresolved references can be fixed using [intention actions](intention-actions.html). 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](#special-comments).

![Example template language intentions for fixing unresolved references](https://resources.jetbrains.com.cn/help/img/idea/2026.2/velocity_intention.png)

> **Note:**
> Comments in such cases are used to provide missing info about the references.

In the latter case, a file with the default name `velocity_implicit.vm` or `freemarker_implicit.ftl` is created. This file starts with the following comment:

```
#* @implicitly included *#
```

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

IntelliJ IDEA provides the following special comments for working with template languages:

FreeMarker:

FreeMarker comments are delimited using either `<#--` and `-->` or `[#--` and `--#]`.

| Comment | Description |
| --- | --- |
| `@implicitly included` |  Any FreeMarker file that starts with this comment is included in all files that are in the same module or its dependencies. Use such a dedicated comments file to define IDE-specific comments, so that they do not pollute your template files.  |
| `@ftlvariable` |  Defines a variable. For example, the following comment declares a variable named `foo` of type `String`, visible only in the specified file:                                 ``` <#-- @ftlvariable name="foo" type="java.lang.String" file="path/to/file" --> ```                                To properly resolve `String` in this case, the module should have JDK attached. Primitive and generic types are supported. The `file` parameter is optional.                                The `@ftlvariable` comment can also use `name=""` (an empty string). In this case, the specified type is treated as the root data model, and all its members are available as variables.     |
| `@ftlroot` |  Defines the path relative to which `import` and `include` directives are resolved. The path is specified relative to any of the directories in the current FTL file's package. Paths inside JARs are also supported, for example:                                 ``` <#-- @ftlroot "path/to.jar!/path/inside/jar" --> ```    |

Velocity:

Velocity comments are delimited using `#*` and `*#`.

| Comment | Description |
| --- | --- |
| `@implicitly included` |  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.  |
| `@vtlvariable` |  Defines a variable. For example, the following comment declares a variable named `foo` of type `String`, visible only in the specified file:                                 ``` #* @vtlvariable name="foo" type="java.lang.String" file="path/to/file" *# ```                                To properly resolve `String` in this case, the module should have JDK attached. Primitive and generic types are supported. The `file` parameter is optional.  |
| `@vtlmacrolibrary` |  Defines the file with template macros relative to the file with this comment. For example, the following comment makes macros from `lib.vm` accessible to code insight in `file.vm`:                                 ``` #* @vtlmacrolibrary path="lib.vm" file="file.vm" *# ```    |
| `@velocityproperties` |  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” *# ```    |

