I use hbs to render some templates in my nestjs app, but I need to save the html renderized into variable and send it to a external API.
In docs (https://docs.nestjs.com/techniques/mvc) I only found how to send the render as a normal response, It works, but I don't know how to save the html as variable.
If you want to have access to the generated HTML before sending it to the client you can use the third parameter of the response render method:
app.controller.ts
import { Get, Controller, Res } from '@nestjs/common';
import { Response } from 'express';
@Controller()
export class AppController {
@Get()
root(@Res() res: Response) {
return res.render(
'index',
{ message: 'Hello world!' },
function (err, html) {
// Here you have access to the generated HTML
res.send(html)
}
);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With