Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
jQuery Templates for the Rails asset pipeline.
branch: master
Failed to load latest commit information.
lib Allow the prefix to be a regular expression.
spec Allow the prefix to be a regular expression.
vendor/assets/javascripts rename plugin to avoid extension conflict with .tmpl engine
.gitignore Add dummy Rails app for testing. Refactor prefix to use Rails.configu…
LICENSE add MIT license Add Code Climate badge.
Rakefile add specs for sprockets engine
jquery-tmpl-rails.gemspec v1.1.0

Code Climate endorse


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 and run bundle.


jQuery templates will be recognized by Sprockets with the .tmpl extension. Place them anywhere in the Sprockets load path.

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

In your application's JavaScript manifest file, require the jQuery Templates plugin followed by your templates. The templates are compiled and named with their Sprockets logical path:

//= require jquery-tmpl
//= require_tree ./templates

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


If the path to all of your templates have a common prefix that you prefer is not included in the template's name, you can set this option in config/application.rb:

config.jquery_templates.prefix = "templates"

That would change the previous example to this:

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

The prefix can also be a regular expression. For example, to use only the name of the file for the template name, regardless of directory structure:

config.jquery_templates.prefix = %r{([^/]*/)*}

Happy templating!


The Sprockets engine was originally derived from the sprockets-jquery-tmpl gem. If you want a similar mechanism for use outside of Rails, take a look at this project.

Something went wrong with that request. Please try again.