Get the template - Apache FreeMarker Manual

Unsupported web browser - Use a modern browser to view this website!

- 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, using its. `getTemplate` method. If you store the example template in the `test.ftlh` file of the earlier set directory, then you can do this:

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

This gives you a `Template` instance that was created by reading `/where/you/store/templates/test.ftlh` and parsing it. The `Template` instance stores the template in parsed form, and not as text. If the template is missing or syntactically incorrect, `getTemplate` will throw exception instead.

`Configuration` caches `Template` instances, so when you call `cfg.getTemplate("test.ftlh")` next time, it probably won't read and parse the template file again, just returns the same `Template` instance as for the first time.

Previous Next