template rendering with node.js and backbone.js

后端 未结 9 1248
孤城傲影
孤城傲影 2021-02-01 08:20

Has anyone found a good solution for developing templates for backbone.js that can be used on the server and the client?

This is really desirable with the backbone.js hi

9条回答
  •  悲&欢浪女
    2021-02-01 09:00

    In terms of choosing a template language, you can pretty much take your pick with any js-based templating language, including Underscore Templates, Mustache or Handlebars - it's trivial to set up templates in a publicly accessible path that your Node.js application also reads when the content is generated server-side.

    My personal favourite is Jade, which comes out of the box with Express - it enforces a very simplistic, expressive coding style.

    You can find a good write-up of how to link together Backbone.js and Express here (using Jade as the template language).

    Most of the examples tend to be how to set up a RESTful application which renders entirely client-side (and is not what you're really after).

    However if you get your web app rendering in Express from templates in a publicly accessible folder (I would recommend keeping views separate - preprocess your templates and hand the html over to your views, so you keep the templates specific) then you'll be able to load them from Backbone.js too, and handle changes using Backbone.js's history stack.

提交回复
热议问题