Configuration
All options are passed to NestDynamicTemplatesModule.forRoot() (or forRootAsync()). Every field is optional.
NestDynamicTemplatesModule.forRoot({
isGlobal: true,
// Only these engines are loaded. Default: { template: ['njk'], language: ['html','mjml','txt'] }
engines: {
template: [TemplateEngineEnum.NUNJUCKS, TemplateEngineEnum.HANDLEBARS],
language: [TemplateLanguageEnum.HTML, TemplateLanguageEnum.MJML, TemplateLanguageEnum.MARKDOWN],
},
// Custom filters/helpers — available in EVERY template engine.
filters: {
formatCurrency: (n: number, ccy: string) =>
new Intl.NumberFormat('en-US', { style: 'currency', currency: ccy }).format(n),
},
// Global values injected into every render (strings, numbers, objects or functions).
globals: {
brandName: 'Acme',
year: () => new Date().getFullYear(),
},
// Raw options forwarded to the underlying engine libraries.
engineOptions: {
template: { njk: { autoescape: true, trimBlocks: true } },
language: { mjml: { validationLevel: 'soft' } },
},
});engines
The enabled list gates which engines are instantiated — this is what keeps peer dependencies optional. List every engine you use and install its package. Rendering with a disabled engine throws TemplateEngineUnavailableError.
engines: {
template: ['njk'], // TemplateEngineEnum values: njk, hbs, ejs, pug
language: ['html', 'mjml', 'txt'], // TemplateLanguageEnum values: html, mjml, md, txt
}The list is replaced, not merged
Passing template: ['hbs'] gives you exactly ['hbs'] — it does not keep the default njk.
filters
Functions usable in any engine. In Nunjucks they're filters ({{ amount | formatCurrency('USD') }}); in Handlebars they're helpers ({{formatCurrency amount 'USD'}}); in EJS/Pug they're callable locals.
globals
Values available without being passed in context on every render. Functions are supported (Nunjucks globals, callable locals elsewhere).
engineOptions
Raw options forwarded straight to the underlying library, keyed by engine:
template.njk→ NunjucksConfigureOptionstemplate.hbs→ Handlebars compile optionstemplate.ejs→ EJS optionstemplate.pug→ Pug optionslanguage.mjml→mjml2htmloptions (e.g.validationLevel)
Async configuration
Use forRootAsync() when options depend on other providers (e.g. ConfigService):
NestDynamicTemplatesModule.forRootAsync({
isGlobal: true,
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
engines: { template: ['njk'], language: ['html', 'mjml'] },
globals: { appUrl: config.get('APP_URL') },
}),
});useClass and useExisting factories are also supported via NestDynamicTemplatesModuleOptionsFactory.
Migrating from v1 config
The v1 enginesOptions block is replaced by the flat filters / globals / engineOptions fields. The old shape still works with a deprecation warning — see the migration guide.