@fastnloud/nest-template
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Description

Template module for Nest that uses Handlebars to render templates.

Installation

$ npm i --save @fastnloud/nest-template

Setup

Import module:

import { TemplateModule } from '@fastnloud/nest-template';
import { Module } from '@nestjs/common';
import * as path from 'path';

@Module({
  imports: [
    TemplateModule.forRoot(path.join(__dirname, 'path', 'to', 'templates')),
  ],
})
export class AppModule {}

A sample template file looks something like this:

<!-- /path/to/templates/dir/template.html.handlebars -->
<!DOCTYPE html>
<html lang="en">
  <body>
    <p>{{ content }}</p>
  </body>
</html>

Usage

import { HandlebarsRenderer } from '@fastnloud/nest-template';
import { Injectable } from '@nestjs/common';

@Injectable()
export class TemplateService {
  constructor(private readonly handlebarsRenderer: HandlebarsRenderer) {}

  async render(): Promise<string> {
    return this.handlebarsRenderer.render(['dir', 'template.html.handlebars'], {
      content: 'hello world',
    });
  }
}

License

nest-template is MIT licensed.

Package Sidebar

Install

npm i @fastnloud/nest-template

Weekly Downloads

37

Version

1.0.1

License

MIT

Unpacked Size

7.95 kB

Total Files

9

Last publish

Collaborators

  • fastnloud