Node.js with Handlebars.js on server and client

前端 未结 7 2461
抹茶落季
抹茶落季 2020-12-02 08:21

I have an app in Node.js using Expressjs and Handlebars as the template engine.

Expressjs uses layouts and then renders views. The layout (layout.hbs) looks like th

7条回答
  •  盖世英雄少女心
    2020-12-02 08:32

    You should use pre-compiled client templates. They are faster executing and allow you to use the same template language on the server and client.

    1. Install handlebars globally npm install handlebars -g
    2. Precompile your templates handlebars client-template1.handlebars -f templates.js
    3. Include templates.js
    4. Execute the template var html = Handlebars.templates["client-template1"](context);

    https://stackoverflow.com/a/13884587/8360

提交回复
热议问题