Skip to content

walski/handlebars.jquery.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

handlebars.jquery.js

This jQuery Plugin lets you easily bind Handlebars.js templates to DOM elements.

It's a simple and lean way to glue a model to a view.

Features

  • write your Handlebars template just inside the DOM element
  • bind a model to the template
  • supports any kind of model that is compatible to jQuery's data() API
  • can render simple collections in combination with collection.jquery.js or compatible collections

Installation

Just include jQuery, Handlebars and handlebars.jquery.js in your HTML Head:

  <!DOCTYPE html>

  <html>
  <head>
    <script src="jquery-1.5.1.min.js" charset="utf-8"></script>
    <script src="handlebars-0.9.0.pre.4.js" charset="utf-8"></script>
    <script src="handlebars.jquery.js" charset="utf-8"></script>
  ...

Usage Examples

Simple example

  ...
  <h1 data-title="It's a headline!">{{title}}</h1>
  ...
  <script style="text/javascript">
    $('h1').template();
  </script>
  ...

Collections

  ...
  <ul>
    <li>Some Fruit: {{name}}</li>
  </ul>
  ...
  <script style="text/javascript">
    var banana = $({});
    banana.data('name', 'Banana');
    var apple = $({}); 
    apple.data('name', 'Green Apple');
    
    var fruits = $.collection(banana, apple);
    $('ul').template();
  </script>
  ...

results in:

  <ul>
    <li>Some Fruit: Banana</li>
    <li>Some Fruit: Green Apple</li>
  </ul>

See the demo folder for more examples.

About

Easy integration of Handlebars.js and jQuery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published