Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


I 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/


Great!

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.


I love it! I Was looking at doing something similar with Scala.


Wow - I think this is great!


thanks! 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.


As 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.


I'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 :)


I 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.


It 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.


While 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


Does anyone use Dust? http://akdubya.github.com/dustjs/



I agree.

But for larger apps Handlebars.js is great because it supports pre-compilation which helps boost performance.


Neat. I didn't know that.

Just to clarify, Handlebars supports server side pre-compilation so that slower clients such as mobile devices can get a bit of a speed boost in the loading process.


Underscore also supports pre-compilation with _.template().




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: