This gem adds the jQuery Templates plugin and a corresponding Sprockets engine to the asset pipeline in Rails => 3.1 applications.
Add it to your gemfile:
gem "jquery-tmpl-rails"
Update your bundle:
bundle install
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");
Happy templating!
The .tmpl
Sprockets engine is based on the sprockets-jquery-tmpl gem. If you want a similar mechanism for use outside of Rails, take a look at this project.