Get the template - FreeMarker Manual

- Home
- Manual
- Java API

- Contribute
- Report a Bug
- Download

Manual
Previous Next

# Get the template

Templates are represented by `freemarker.template.Template` instances. Typically you obtain a `Template` instance from the `Configuration` instance. Whenever you need a template instance you can get it with its `getTemplate` method. Store the example template in the `test.ftl` file of the earlier set directory, then you can do this:

    Template temp = cfg.getTemplate("test.ftl");

When you call this, it will create a `Template` instance corresponds to `test.ftl`, by reading `/where/you/store/templates/test.ftl` and parsing (compile) it. The `Template` instance stores the template in the parsed form, and not as text.

`Configuration` caches `Template` instances, so when you get `test.ftl` again, it probably won't read and parse the template file again, just returns the same `Template` instance as for the first time.

Previous Next