8000 GitHub - fastnloud/nest-template
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fastnloud/nest-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published
0