Skip to content

wesleytodd/jQuery-Templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jQuery Templates

A direct rip-off of Underscore templates. I copied everything, including the unit tests. See the Underscore documentation for more information.

Example

var compiled = $.template("hello: <%= name %>");
compiled({name : 'moe'});
=> "hello: moe"

var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
$.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"

var template = $.template("<b><%- value %></b>");
template({value : '<script>'});
=> "<b>&lt;script&gt;</b>"

var compiled = $.template("<% print('Hello ' + epithet); %>");
compiled({epithet: "stooge"});
=> "Hello stooge."

Why?

I have often wanted to use some nice templates in my jQuery code. The "official" templates that were to be included with jQuery were deprecated, and including two libraries with similar functionality is not good practice.

Tests

Run:

npm install
grunt

This runs the tests, lints and minifies the source and starts a test server at http://localhost:8000/test.

About

jQuery based rip-off of Underscore templates

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published