7 ms·
If you are using backbone and don't need a complex templating engine, just use _.template. It comes free with underscore, which is a requirement for backbone.
by chime 14y ago
If you are using backbone and don't need a complex templating engine, just use _.template. It comes free with underscore, which is a requirement for backbone.
- skylan_q 14y agoAs someone who is learning to use backbone and underscore templates, I'll second this. But I've got to say that Handlebars looks like another decent option.
- nilliams 14y agoI'd go so far as to say 'just use Handlebars', as at some point you will need an 'each' construct which underscore templates don't provide. They're okay for minimal templates that are akin to string interpolation, but as soon as you 'get serious' you end up writing things like <% _.each(things, function(thing){ %> which is just horrible. Mustache-based templates (mustache, handlebars, hogan.js), though they are a bitch in their schooling you on being 'logicless' really are in my experience, very practical. And please no-one downvote me by nitpicking that templates can never be truly logicless, I know that :)
- smhinsey 14y agoIt might be better to say that it's free of control flow structures[0]. This is my preferred approach but it can definitely take some adaptation if you're used to doing a lot more in your views. [0] I wonder if partials count? I don't know that all of the moustache derivatives have them anyway.
- PStamatiou 14y agoWhile I do love and use Handlebars for our Backbone app, if you find yourself using a lot of such each block helpers... you may want to create a new Backbone view to handle that
- sophacles 14y agoI tend to prefer mustache, because I can use the same template code server-side and client side trivially. It's nice for cases where you are pre-filling stuff, or where you want to render for no-script situations.
- smagch 14y agoDoes anyone use Dust? http://akdubya.github.com/dustjs/ http://akdubya.github.com/dustjs/
- jc123 14y agoSome discussion http://news.ycombinator.com/item?id=3349845 http://news.ycombinator.com/item?id=3349845
- salmanapk 14y agoI agree. But for larger apps Handlebars.js is great because it supports pre-compilation which helps boost performance.
- jakejake 14y agoI wrote a code generator that generates a Backbone.js app based on a MySQL schema. It uses PHP, but mainly all the PHP does is provide the REST API for backbone. I'd like to think I've done a decent job with the organization of the client code. I went with a pretty bare-bones setup using Underscore templates (since they come for free with Backbone) and using the built-in features without additional extensions (like model binding). But I was able to get some fun stuff in there like collection pagination. If anybody would care to take a look and give me some feedback there's a live demo so you don't have to install anything. It's at http://phreeze.com/ http://phreeze.com/
- rexreed 14y agoWow - I think this is great!
- jakejake 14y agothanks! any feedback or help is absolutely welcome. this is my first major github project so i'm still figuring things out (long time svn user, new to git) but the framework development is very active and in use on production servers.
- ebiester 14y agoI love it! I Was looking at doing something similar with Scala.
- uniclaude 14y agoGreat! I made something similar three years ago, but I admit that even if it was good enough for my freelance jobs, it was nowhere as polished as yours. I really like it. Thanks for sharing.