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

后端 未结 6 1976
陌清茗
陌清茗 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:21

    For convenience, registerPartials provides a quick way to load all partials from a specific directory:

    var hbs = require('hbs');
    hbs.registerPartials(__dirname + '/views/partials');
    

    Partials that are loaded from a directory are named based on their filename, where spaces and hyphens are replaced with an underscore character:

    template.html      -> {{> template}}
    template 2.html    -> {{> template_2}}
    login view.hbs     -> {{> login_view}}
    template-file.html -> {{> template_file}}
    

    Cheers!

提交回复
热议问题