Created
March 4, 2012 12:34
-
-
Save cecilemuller/1972811 to your computer and use it in GitHub Desktop.
Dynamic template from an arbitrary string, using Jquery Templates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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