How to configure partials and layouts for Handlebars in Sails.js?

后端 未结 7 872
暖寄归人
暖寄归人 2020-12-25 08:27

I run Sails 0.9.7 and have installed Handlebars which is supported by Consolidate.js and therefore is supported by Sails

I can serve pages from .handlebars

相关标签:
7条回答
  • 2020-12-25 09:25

    I'm using the answers given above, but I seem to have made partials work with sails 0.9.8 with no hacks.

    Here's what I have.

    Config/views.js => engine: "handlebars"

    views/home/index.handlebars => main file using the partial.

    views/home/partials/partial.handlebars => partial being used.

    Then as long as you use something like this, it works perfectly. res.view({ partials: { partial: 'partials/partial', footer: 'partials/footer' } })

    The paths are relative to the template file called by default. So if you want different partials per controller you use partials/ and if you want global partials for all templates you use ../partials/

    Obviously this is completely unto you as you need to specify every partial manually in the controller anyway.

    0 讨论(0)
提交回复
热议问题