API / Apache FreeMarker Interview questions
What is the purpose of TemplateLoader, and what types are available?
TemplateLoader is the abstraction that decides where template source text actually comes from, so Configuration.getTemplate() never needs to know or care whether a template lives on disk, inside a jar, or in memory.
| Implementation | Loads templates from |
| FileTemplateLoader | A directory on the filesystem |
| ClassTemplateLoader | The Java classpath - convenient when templates are packaged inside a jar |
| StringTemplateLoader | In-memory strings registered programmatically - handy for tests or dynamically generated templates |
| MultiTemplateLoader | A chain of other TemplateLoaders, tried in order until one finds the template |
The freemarker-servlet extension additionally provides a webapp-aware loader that reads templates from a web application's resource path. Choosing the right loader (or combination, via MultiTemplateLoader) is what lets the same application ship templates inside a jar for production while still allowing a filesystem override during local development.
More Related questions...