Big News: Socket Selected for OpenAI's Cybersecurity Grant Program.Details
Socket
Book a DemoSign in
Socket

@gboutte/nestjs-hbs

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gboutte/nestjs-hbs

This package provide a service to render handlebars templates for nestjs.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

Installation

npm install @gboutte/nestjs-hbs

Configuration

@Module({
  imports: [
    HandlebarsModule.forRoot({
      templateDirectory: 'templates',
      partialDirectory: 'templates/partials',
      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
partialDirectoryThis will load all files as partials. If you have a file named myPartial.hbs, a partial named myPartial will be added.
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 used inside the template
renderThis will render a template string using handlebars- html: the template
- parameters: an array of parameters that will be used inside the template string
Here is an example
@Controller()
export class AppController {
  constructor(private readonly hbsService: HandlebarsService) {}

  @Get()
  async getTest() {
    return this.hbsService.renderFile('hello.hbs', { name: 'John Doe'});
  }
  @Get('template-string')
  async getTest() {
    return this.hbsService.render('<h1>Hello {{name}}</h1>', { name: 'John Doe'});
  }
}

Keywords

nestjs

FAQs

Package last updated on 31 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts