@gboutte/nestjs-hbs
TypeScript icon, indicating that this package has built-in type declarations

0.0.15 • Public • Published

Installation

npm install @gboutte/nestjs-hbs

Configuration

@Module({
  imports: [
    HandlebarsModule.forRoot({
      templateDirectory: 'templates',
      compileOptions: {},
      templateOptions: {},
    })
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
Description
templateDirectory This will define the folder where the templates files are located
compileOptions The templates options can be found on: https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access
templateOptions The compile options can be found on https://handlebarsjs.com/api-reference/compilation.html#handlebars-compile-template-options
helpers An array of helpers to add in handlebars, each helpers has a property name and fn

Usage

You can use the HandlebarsService, there is currently two methods

Description Parameters
renderFile This will render a handlebars template (located in the template folder previously defined), and will return the rendered string. - file: the template file to render
- parameters: an array of parameters that will be user inside the template
render This will render a template string using handlebars - html: the template
- parameters: an array of parameters that will be user inside the templatestring
Here is an example
@Controller()
export class AppController {
  constructor(private readonly hbsService: HandlebarsService) {}

  @Get()
  async getTest() {
    return this.hbs.renderFile('hello.hbs', { name: 'John Doe'});
  }
}

Package Sidebar

Install

npm i @gboutte/nestjs-hbs

Weekly Downloads

28

Version

0.0.15

License

MIT

Unpacked Size

98.9 kB

Total Files

24

Last publish

Collaborators

  • gboutte