Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gboutte/nestjs-hbs
A library that allow you tu use handlebar template to generate HTML inside a wrapper for nestjs.
https://github.com/gboutte/nestjs-hbs
handlebars nestjs
Last synced: about 2 months ago
JSON representation
A library that allow you tu use handlebar template to generate HTML inside a wrapper for nestjs.
- Host: GitHub
- URL: https://github.com/gboutte/nestjs-hbs
- Owner: gboutte
- Created: 2022-10-25T21:44:37.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-07T19:25:59.000Z (9 months ago)
- Last Synced: 2024-10-11T22:37:15.433Z (3 months ago)
- Topics: handlebars, nestjs
- Language: TypeScript
- Homepage:
- Size: 53.7 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# Installation
```shell
npm install @gboutte/nestjs-hbs
```# Configuration
```ts
@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
```ts
@Controller()
export class AppController {
constructor(private readonly hbsService: HandlebarsService) {}@Get()
async getTest() {
return this.hbs.renderFile('hello.hbs', { name: 'John Doe'});
}
}
```