jquery-tmpl-rails: jQuery Templates for the Rails asset pipeline

There are myriad of JavaScript templating libraries available. The one officially adopted by jQuery is the jQuery Templates plugin. I have released jquery-tmpl-rails, a gem which adds the plugin and a corresponding Sprockets engine to the asset pipeline for Rails 3.1 applications.


Install it the usual way by adding it to your Gemfile:

gem "jquery-tmpl-rails"

Then run the bundle command from the shell.


Place individual jQuery templates in their own files with the .tmpl extension:

<!-- app/assets/javascripts/tmpl/author.tmpl -->
<div class="author">${name}</div>

In your manifest file, require the plugin followed by your individual templates. The templates are compiled and named with their Sprockets logical path:

//= require jquery-tmpl
//= require tmpl/author

$.tmpl("tmpl/author", { name: "Jimmy" }).appendTo("#author");

Feedback is appreciated! Happy templating!