/ Published in: jQuery
Important: this snipplet has moved to Github.
Method 1: Static template via a SCRIPT tag, using Jquery Templates
Method 2: Dynamic template from an arbitrary string, using Jquery Templates
Both methods work even without the plus extension of the Templates plugin
Expand |
Embed | Plain Text
/** * Method 1: Static template, using a SCRIPT tag. */ //HTML: <script id="MyStaticTemplate" type="text/x-jquery-tmpl"> <div>Hello ${hello}</div> </script> //Javascript: var MyData = {hello: "world"}; $("#MyStaticTemplate").tmpl(MyData).appendTo("#contents"); /** * Method 2: Dynamic, from a string (which could be stored in an external * file or even in a database] */ 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");
You need to login to post a comment.
