<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://70.231.62.181/index.php?action=history&amp;feed=atom&amp;title=JavaScript_templating</id>
	<title>JavaScript templating - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://70.231.62.181/index.php?action=history&amp;feed=atom&amp;title=JavaScript_templating"/>
	<link rel="alternate" type="text/html" href="http://70.231.62.181/index.php?title=JavaScript_templating&amp;action=history"/>
	<updated>2026-06-21T13:41:41Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>http://70.231.62.181/index.php?title=JavaScript_templating&amp;diff=13783385&amp;oldid=prev</id>
		<title>imported&gt;Frap: Hyphen to dash for ranges</title>
		<link rel="alternate" type="text/html" href="http://70.231.62.181/index.php?title=JavaScript_templating&amp;diff=13783385&amp;oldid=prev"/>
		<updated>2025-11-03T11:57:15Z</updated>

		<summary type="html">&lt;p&gt;Hyphen to dash for ranges&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description|Client side data binding method implemented with JavaScript}}&lt;br /&gt;
{{no footnotes|date=July 2013}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;JavaScript templating&amp;#039;&amp;#039;&amp;#039; refers to the [[client side]] [[data binding]] method implemented with the [[JavaScript|JavaScript language]]. This approach became popular thanks to JavaScript&amp;#039;s increased use, its increase in client processing capabilities, and the trend to outsource computations to the client&amp;#039;s web browser. Popular JavaScript templating libraries are [[AngularJS]], [[Backbone.js]], [[Ember.js]], [[Handlebars.js]], [[JSX (JavaScript)|JSX]] (used by [[React (JavaScript library)|React]]), [[Vue.js]] and [[Mustache.js]]. A frequent practice is to use double [[curly bracket]]s (i.e. &amp;lt;nowiki&amp;gt;{{key}}&amp;lt;/nowiki&amp;gt;) to call values of the given key from data files, often [[JSON]] objects.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
All examples use an external file &amp;lt;code&amp;gt;presidents.json&amp;lt;/code&amp;gt; with following contents&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
  &amp;quot;presidents&amp;quot; : [&lt;br /&gt;
      { &amp;quot;name&amp;quot;: &amp;quot;Washington&amp;quot;, &amp;quot;firstname&amp;quot;: &amp;quot;George&amp;quot;, &amp;quot;born&amp;quot;: &amp;quot;1732&amp;quot;, &amp;quot;death&amp;quot;: &amp;quot;1799&amp;quot; },&lt;br /&gt;
      { &amp;quot;name&amp;quot;: &amp;quot;Lincoln&amp;quot;, &amp;quot;firstname&amp;quot;: &amp;quot;Abraham&amp;quot;, &amp;quot;born&amp;quot;: &amp;quot;1809&amp;quot;, &amp;quot;death&amp;quot;: &amp;quot;1865&amp;quot; }&lt;br /&gt;
  ]&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
All examples will produce the following HTML [[Unordered list|list]]:&lt;br /&gt;
&lt;br /&gt;
* Washington (1732–1799)&lt;br /&gt;
* Lincoln (1809–1865)&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Library !! HTML Code !! Explanation&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;10%&amp;quot;|&lt;br /&gt;
[https://github.com/webdevelopers-eu/jquery-dna-template DNA Template]&lt;br /&gt;
| width=&amp;quot;65%&amp;quot;|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot; line&amp;gt;&lt;br /&gt;
&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; href=&amp;quot;.../template.css&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;.../jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;.../jquery.template.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; ➊&lt;br /&gt;
&lt;br /&gt;
Our favorite presidents are:&lt;br /&gt;
&amp;lt;ul id=&amp;quot;target&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;li template=&amp;quot;[presidents]&amp;quot; z-var=&amp;quot;name ., born ., death .&amp;quot;&amp;gt;&lt;br /&gt;
     ${name} (${born}-${death})&lt;br /&gt;
    &amp;lt;/li&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt; ➋&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
    $.getJSON(&amp;#039;.../presidents.json&amp;#039;, function(data) {&lt;br /&gt;
        $(&amp;#039;#target&amp;#039;).template(data);&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/script&amp;gt; ➌&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;|&lt;br /&gt;
➊ Load the necessary resources, including required [[jQuery]]&amp;lt;br /&amp;gt;&lt;br /&gt;
➋ The HTML code with &amp;lt;code&amp;gt;template&amp;lt;/code&amp;gt; attribute marking for-each subtemplate and &amp;lt;code&amp;gt;z-var&amp;lt;/code&amp;gt; replacement instructions.&amp;lt;br /&amp;gt;&lt;br /&gt;
➌ Load JSON data from &amp;lt;code&amp;gt;presidents.json&amp;lt;/code&amp;gt; and apply data to the HTML template with id attribute &amp;quot;&amp;lt;code&amp;gt;target&amp;lt;/code&amp;gt;&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
| width=&amp;quot;10%&amp;quot;|&lt;br /&gt;
[[Mustache.js]]&lt;br /&gt;
| width=&amp;quot;65%&amp;quot;|&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;html&amp;quot; line&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;.../jquery.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script src=&amp;quot;.../mustache.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; ➊&lt;br /&gt;
&lt;br /&gt;
Our favorite presidents are:&lt;br /&gt;
&amp;lt;ul id=&amp;quot;target&amp;quot;&amp;gt;&amp;lt;/ul&amp;gt; ➋&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script id=&amp;quot;president-template&amp;quot; type=&amp;quot;text/template&amp;quot;&amp;gt;&lt;br /&gt;
    {{#presidents}}&lt;br /&gt;
        &amp;lt;li&amp;gt;{{name}} ({{born}}-{{death}})&amp;lt;/li&amp;gt;&lt;br /&gt;
    {{/presidents}}&lt;br /&gt;
&amp;lt;/script&amp;gt; ➌&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
    $.getJSON(&amp;#039;.../presidents.json&amp;#039;, function(data) {&lt;br /&gt;
        var template = $(&amp;#039;#president-template&amp;#039;).html();&lt;br /&gt;
        var info = Mustache.to_html(template, data);&lt;br /&gt;
        $(&amp;#039;#target&amp;#039;).html(info);&lt;br /&gt;
    });&lt;br /&gt;
&amp;lt;/script&amp;gt; ➍&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
| valign=&amp;quot;top&amp;quot;|&lt;br /&gt;
➊ Load the necessary libraries, here [[mustache.js]] and [[jQuery]]&amp;lt;br /&amp;gt;&lt;br /&gt;
➋ The HTML code provides a &amp;quot;target&amp;quot; to insert generated contents into.&amp;lt;br /&amp;gt;&lt;br /&gt;
➌ Provide a template named &amp;quot;president-template&amp;quot;. &amp;lt;br /&amp;gt;&lt;br /&gt;
➍ Last is a function grasping the JSON data, and for each president&amp;#039;s subitem, grasping one template and filling it to finally select the HTML page&amp;#039;s target appending the whole to it. &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Templating becomes useful when the information distributed may change, is too large to be maintained in various HTML pages by available human resources and not large enough to require heavier server-side templating.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Comparison of web template engines]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
* {{citation|url=https://developer.mozilla.org/en-US/docs/JavaScript_templates|title=JavaScript templates|publisher=Mozilla Developer Network|year=2013}}&lt;br /&gt;
* {{citation|url=http://engineering.linkedin.com/frontend/client-side-templating-throwdown-mustache-handlebars-dustjs-and-more|title=The client-side templating throwdown: mustache, handlebars, dust.js, and more|last=Basavaraj|first=veena|publisher=Linkedin.com|year=2012}}&lt;br /&gt;
* {{citation|url=http://iviewsource.com/codingtutorials/introduction-to-javascript-templating-with-mustache-js/ |title=Introduction to JavaScript Templating (video tutorial) with Mustache.js |last=Villalobos |first=Ray |year=2012 |publisher=ViewSource.com |url-status=dead |archiveurl=https://web.archive.org/web/20130513103343/http://iviewsource.com/codingtutorials/introduction-to-javascript-templating-with-mustache-js/ |archivedate=2013-05-13 }}&lt;br /&gt;
* {{citation|url=http://net.tutsplus.com/tutorials/javascript-ajax/best-practices-when-working-with-javascript-templates/ |title=Best Practices When Working With JavaScript Templates |last=Burgess |first=Andrew |year=2012|publisher=Net.tutsplus.com}}&lt;br /&gt;
* {{citation|url=http://viget.com/extend/benchmarking-javascript-templating-libraries|title=Benchmarking Javascript Templating Libraries|year=2009|last=Landau|first=Brian}}&lt;br /&gt;
* http://www.jquery4u.com/javascript/10-javascript-jquery-templates-engines/&lt;br /&gt;
* {{citation|url=https://vuejs.org/v2/guide/comparison.html|title=Comparison with Other Frameworks|publisher=Vue.js|access-date=11 December 2018}}&lt;br /&gt;
{{JS templating}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Template engines]]&lt;br /&gt;
[[Category:JavaScript libraries]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Frap</name></author>
	</entry>
</feed>