Best strategy to use HAML template with Backbone.js

后端 未结 8 1963
别那么骄傲
别那么骄傲 2021-01-29 23:23

Im getting into Backbone.js to structure the javascript code for my project and I love HAML for templating on the backend(rails), so Id like to use it for Backbone Views templat

8条回答
  •  忘掉有多难
    2021-01-29 23:29

    I know this would somewhat going around the question but here we go :)

    I my rails app I use haml for all views on the backend. It is awesome. For some reasons (mainly i18n), I do not like to use templates on the client side. This is how I do it:

    • create all your template in ruby haml and store them into script tag with a funky type (i use text/js-template). This will create prerendered html that you can play with with jquery and backbone.
    • when you create your backbone views, load the stored template and append it to your document
    • Render your view by altering the preexisting template

    You deal only with html and jQuery is awesome for that. For some views that do not requires i18n, I use underscore templating because it's already there.

    As for haml templating performance, it seems mustache and handlebars are faster.

提交回复
热议问题