0.0.15 • Published 2 years ago

@gboutte/nestjs-hbs v0.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

0.0.13

2 years ago

0.0.14

2 years ago

0.0.15

2 years ago

0.0.10

2 years ago

0.0.11

2 years ago

0.0.9

2 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago