npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ackplus/nest-dynamic-templates

v1.1.16

Published

A powerful and flexible dynamic template rendering library for NestJS applications with support for Nunjucks, Handlebars, EJS, MJML, and more.

Readme

@ackplus/nest-dynamic-templates

A powerful and flexible dynamic template rendering library for NestJS applications. Support for multiple template engines (Nunjucks, Handlebars, EJS, Pug) and content languages (HTML, MJML, Markdown, Text), with built-in database storage and layout management.

✨ Features

  • 🔌 Multiple Engines - Support for Nunjucks, Handlebars, EJS, and Pug
  • 📝 Multi-Format - Render HTML, MJML, Markdown, or Plain Text
  • 🗄️ Database Storage - Store templates in your database (TypeORM support)
  • 🎨 Layout Support - Create reusable layouts for your templates
  • 🌍 Scope & Locale - Manage templates by scope (system/user/tenant) and locale (en/es/etc.)
  • 🚀 Dynamic Rendering - Render templates with dynamic context at runtime

📦 Installation

npm install @ackplus/nest-dynamic-templates
# or
pnpm add @ackplus/nest-dynamic-templates
# or
yarn add @ackplus/nest-dynamic-templates

Peer Dependencies

You must install the necessary peer dependencies depending on which engines and database you use:

# Core dependencies
npm install @nestjs/common @nestjs/core @nestjs/typeorm typeorm reflect-metadata

# Template Engines (install at least one)
npm install nunjucks @types/nunjucks
# OR
npm install handlebars
# OR
npm install ejs @types/ejs
# OR
npm install pug @types/pug

# Language Support (optional)
npm install mjml @types/mjml      # For MJML support
npm install htmlparser2           # For HTML processing

🚀 Quick Start

1. Import Module

Import NestDynamicTemplatesModule into your root AppModule. You must configure it with TypeORM.

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { NestDynamicTemplatesModule, TemplateEngineEnum, TemplateLanguageEnum } from '@ackplus/nest-dynamic-templates';

@Module({
  imports: [
    TypeOrmModule.forRoot({
      // ... your database config
    }),
    NestDynamicTemplatesModule.forRoot({
      engines: {
        template: [TemplateEngineEnum.NUNJUCKS], // Enable specific engines
        language: [TemplateLanguageEnum.HTML, TemplateLanguageEnum.MJML]
      },
      isGlobal: true, // Optional: make module global
    }),
  ],
})
export class AppModule {}

2. Create a Template

You can create templates programmatically using the TemplateService.

import { Injectable } from '@nestjs/common';
import { TemplateService, TemplateEngineEnum, TemplateLanguageEnum } from '@ackplus/nest-dynamic-templates';

@Injectable()
export class MyService {
  constructor(private readonly templateService: TemplateService) {}

  async createWelcomeTemplate() {
    await this.templateService.createTemplate({
      name: 'welcome-email',
      scope: 'system', // 'system' or custom scope
      locale: 'en',
      subject: 'Welcome, {{ name }}!',
      content: '<h1>Hello {{ name }}</h1><p>Welcome to our platform.</p>',
      engine: TemplateEngineEnum.NUNJUCKS,
      language: TemplateLanguageEnum.HTML,
      type: 'email',
    });
  }
}

3. Render a Template

Render a stored template by name.

async renderEmail(userName: string) {
  const result = await this.templateService.render({
    name: 'welcome-email',
    scope: 'system',
    locale: 'en',
    context: {
      name: userName,
    },
  });

  console.log(result.subject); // "Welcome, John!"
  console.log(result.content); // "<h1>Hello John</h1><p>Welcome to our platform.</p>"
}

📚 API Reference

TemplateService

The main service for managing and rendering templates.

render(options: RenderTemplateDto)

Renders a template stored in the database.

const output = await templateService.render({
  name: 'my-template',
  scope: 'system',
  locale: 'en',
  context: { foo: 'bar' },
});

renderContent(options: RenderContentTemplateDto)

Renders raw content string directly without fetching from the database.

const html = await templateService.renderContent({
  content: 'Hello {{ name }}',
  engine: TemplateEngineEnum.NUNJUCKS,
  context: { name: 'World' },
});

createTemplate(data: CreateTemplateDto)

Creates a new system template.

updateTemplate(id: string, updates: Partial<CreateTemplateDto>)

Updates an existing template. If you try to update a system template without permission, it may create a scoped override instead.

TemplateLayoutService

Manage reusable layouts (e.g., email wrappers with header/footer).

createLayout(data: CreateTemplateLayoutDto)

Create a new layout.

await layoutService.createLayout({
  name: 'main-layout',
  content: '<html><body>{{ content }}</body></html>', // {{ content }} is the placeholder
  engine: TemplateEngineEnum.NUNJUCKS,
});

⚙️ Configuration Options

When importing the module, you can configure the enabled engines:

NestDynamicTemplatesModule.forRoot({
  engines: {
    // Template Logic Engines
    template: [
      TemplateEngineEnum.NUNJUCKS, 
      TemplateEngineEnum.HANDLEBARS, 
      TemplateEngineEnum.EJS, 
      TemplateEngineEnum.PUG
    ],
    // Output Language Processors
    language: [
      TemplateLanguageEnum.HTML, 
      TemplateLanguageEnum.MJML, 
      TemplateLanguageEnum.TEXT, 
      TemplateLanguageEnum.MARKDOWN
    ]
  }
})

📄 License

This project is licensed under the MIT License.