Express.js hbs module - register partials from .hbs file

后端 未结 6 1975
陌清茗
陌清茗 2020-12-04 16:05

I\'m using the handlebars.js hbs wrapper in express.js. I have templates working fine, but I\'m needing to add in partials to be rendered with my views.

I\'d like to

6条回答
  •  星月不相逢
    2020-12-04 16:10

    Looks like creating a variable and pulling in the template code manually works:

    var hbs = require('hbs')
      , fs = require('fs')
      , headerTemplate = fs.readFileSync(__dirname + '/views/_header.hbs', 'utf8');
    

    and later:

    hbs.registerPartial('headPartial', headerTemplate); 
    

提交回复
热议问题