node express how to render handlebars html page to file

前端 未结 3 974
陌清茗
陌清茗 2020-12-16 00:48

I want to convert some html page to pdf via wkhtmltopdf. However, the html page I want to convert to pdf is dynamically generated using handlebars.

So I think one s

3条回答
  •  眼角桃花
    2020-12-16 01:36

    Code above from Alex works perfect. However, my confusion was: I was using 'express-handlebars' and not 'handlebars'. Now, what I can understand is Express-Handlebars is an implementation of Handlebars for an Express application, which I´m using. I just didn't find a way to use the 'compile()' method in Express-Handlebars, so I ended up installing Handlebars (standalone) and used it to compile my (html) template and save the result to disk, just as Alex explained above.

    In summary: 1) I know Express-Handlebars is Handlebars for Express app. 2) I don't know how to use "compile()" method just from express-handlebars, so I ended up installing Handlebars (from npm) and using it on the server to produce my html file (from template) and save it to disk. 3) Of course I installed and use Express-Handlebars everywhere to serve my pages in my Express app; just installed Handlebars to produce my html (in the server) with "compile()" method and save the result to disk.

    Hope this is understandable. Thanks again and bye ...

提交回复
热议问题