0.0.15 • Published 8 months ago

@gboutte/nestjs-hbs v0.0.15

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

Installation

npm install @gboutte/nestjs-hbs

Configuration

@Module({
  imports: [
    HandlebarsModule.forRoot({
      templateDirectory: 'templates',
      compileOptions: {},
      templateOptions: {},
    })
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}
Description
templateDirectoryThis will define the folder where the templates files are located
compileOptionsThe templates options can be found on: https://handlebarsjs.com/api-reference/runtime-options.html#options-to-control-prototype-access
templateOptionsThe compile options can be found on https://handlebarsjs.com/api-reference/compilation.html#handlebars-compile-template-options
helpersAn 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

DescriptionParameters
renderFileThis 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
renderThis 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'});
  }
}
0.0.12

9 months ago

0.0.13

8 months ago

0.0.14

8 months ago

0.0.15

8 months ago

0.0.10

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago