title: What good template language is supported in JavaScript?
body: <p>Templates are a pretty healthy business in established programming languages, but are there any good ones that can be processed in JavaScript?</p>
  
  <p>By "template" I mean a document that accepts a data object as input, inserts the data into some kind of serialized markup language, and outputs the markup. Well-known examples are <a href="http://en.wikipedia.org/wiki/JavaServer_Pages" rel="nofollow noreferrer">JSP</a>, the original PHP, <a href="http://en.wikipedia.org/wiki/XSLT" rel="nofollow noreferrer">XSLT</a>.</p>
  
  <p>By "good" I mean that it's declarative and easy for an HTML author to write, that it's robust, and that it's supported in other languages too. Something better than the options I know about. Some examples of "not good":</p>
  
  <hr>
  
  <p>String math:</p>
  
  <pre><code>element.innerHTML = "&lt;p&gt;Name: " + data.name
      + "&lt;/p&gt;&lt;p&gt;Email: " + data.email + "&lt;/p&gt;";
  </code></pre>
  
  <p>clearly too unwieldy, HTML structure not apparent.</p>
  
  <hr>
  
  <p>XSLT:</p>
  
  <pre><code>&lt;p&gt;&lt;xsl:text&gt;Name: &lt;/xsl:text&gt;&lt;xsl:value-of select="//data/name"&gt;&lt;/p&gt;
  &lt;p&gt;&lt;xsl:text&gt;Email: &lt;/xsl:text&gt;&lt;xsl:value-of select="//data/email"&gt;&lt;/p&gt;
  </code></pre>
  
  <p>// Structurally this works well, but let's face it, XSLT confuses HTML developers.</p>
  
  <hr>
  
  <p>Trimpath:</p>
  
  <pre><code>&lt;p&gt;Name: ${data.name}&lt;/p&gt;&lt;p&gt;Email: ${data.email}&lt;/p&gt;
  </code></pre>
  
  <p>// This is nice, but the processor is only supported in JavaScript, and the language is sort of primitive (<a href="http://code.google.com/p/trimpath/wiki/JavaScriptTemplateSyntax" rel="nofollow noreferrer">http://code.google.com/p/trimpath/wiki/JavaScriptTemplateSyntax</a>).</p>
  
  <hr>
  
  <p>I'd love to see a subset of JSP or ASP or PHP ported to the browser, but I haven't found that.</p>
  
  <p>What are people using these days in JavaScript for their templating?</p>
  
  <h2>Addendum 1 (2008)</h2>
  
  <p>After a few months there have been plenty of workable template languages posted here, but most of them aren't usable in any other language. Most of these templates couldn't be used outside a JavaScript engine.</p>
  
  <p>The exception is Microsoft's -- you can process the same ASP either in the browser or in any other ASP engine. That has its own set of portability problems, since you're bound to Microsoft systems. I marked that as the answer, but am still interested in more portable solutions.</p>
  
  <h2>Addendum 2 (2020)</h2>
  
  <p>Dusting off this old question, it's ten years later, and Mustache is widely supported in dozens of languages. It is now the current answer, in case anyone is still reading this.</p>