Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created March 4, 2012 12:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save cecilemuller/1972811 to your computer and use it in GitHub Desktop.
Dynamic template from an arbitrary string, using Jquery Templates
/**
* Dynamic template from an arbitrary string
* (which could be stored in an external file or even in a database).
*
* Works even without the "plus" extension of the Templates plugin.
* http://github.com/nje/jquery-tmpl
*/
var MyData = {hello: "world"};
$.template("MyInlineTemplate", "<div>Hello ${hello}</div>");
$.tmpl("MyInlineTemplate", MyData).appendTo("#contents");
/**
* Note that static templates cannot be called using the dynamic method,
* therefore this would not work:
*/
$.tmpl("MyStaticTemplate", MyData).appendTo("#contents");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment