1.0.1 • Published 11 months ago

@fastnloud/nest-template v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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.

1.0.1

11 months ago

1.0.0

1 year ago

0.0.3

1 year ago

0.0.1

1 year ago

0.0.2

1 year ago