Handlebars and Mustache Template Playground
Pick Handlebars or Mustache, type a template, paste JSON data, add partials, and watch the output render as HTML or text, with any template or JSON error reported by line and column.
Runs in your browser. Your files never leave your device. See how to check
…
How to do it
- 1Language
Choose Handlebars or Mustache.
- 2Template
Write or open the template.
- 3Data
Paste or open the JSON data.
- 4Partials
Add any named partials.
- 5Output
Check the render and download or copy it.
About this tool
The Handlebars and Mustache Template Playground is a scratch pad for logic-less templates of the kind used in email builders, static site generators, invoice systems and front-end code. The left side has three tabs: the template, the data as JSON, and a list of named partials. The right side shows the rendered output, either as HTML in a sandboxed frame that cannot run scripts, or as plain text, with the raw source of the output underneath. Every change re-renders at once, and a green line confirms that the template rendered without errors. The rendering is done by a small engine written for this page, not by the Handlebars or Mustache libraries, and it never evaluates code from the template. A language switch chooses the rules. In Mustache mode you get variables, triple braces and the ampersand form for unescaped output, sections that repeat over lists or show for true values, inverted sections, comments, partials, and the standalone-line rule that removes the blank line a section tag would otherwise leave. Names are looked up through the whole context stack, as Mustache does. In Handlebars mode you also get the if, unless, each and with block helpers with else, the @index, @key, @first, @last and @root data variables, ../ paths to the parent context, sub-expressions in brackets and hash arguments such as indent=2. Handlebars mode looks names up only in the current context unless you use ../ or @root, which matches how Handlebars itself resolves them by default. The inline helpers are a fixed set: eq, ne, gt, lt, gte, lte, and, or, not, upper, lower, capitalize, trim, json, join, length, default, concat, lookup, add, subtract, multiply, divide, fixed and date. The reference card at the bottom lists them and the data paths your template reads, including the ones passed into helpers, such as qty and price in the invoice.
Errors you can act on
If the template has an unclosed tag, unsupported syntax such as else if, a section that is never closed, a closing tag that does not match its opening tag, an else outside a block, an unknown helper or a missing partial, the output panel shows the message with its line and column and the template editor marks that line. A JSON syntax error is reported in the same way against the data tab. In Mustache mode, a tag with more than one word explains that helpers need Handlebars mode.
The invoice example
The playground opens with an invoice. The data holds invoice number INV-1042, the customer Maya Patel of Brightline Studio and two items: Logo design, 1 at 450, and Business cards (box), 3 at 28.5. The template prints a numbered row for each item with {{add @index 1}}, formats the price with {{fixed price}} and the line total with {{fixed (multiply qty price)}}, so the rows read 450.00 and 85.50. An {{else}} inside the each block would print "No items" for an empty list. A footer partial uses {{upper customer.name}} and renders "Thank you, MAYA PATEL. Payment due in 14 days." The Mustache example button loads the classic repos template, which renders "Hello Chris!", a line for each of resque, hub and rip, and a signature partial.
Working with files
Open a template from .hbs, .handlebars, .mustache, .html, .txt or .tpl, save it back with the right extension, open a JSON file, and tidy the JSON with Format JSON. The output can be downloaded as output.html or output.txt, copied to the clipboard or printed to PDF. The whole set of template, data and partials can be saved as a project in this browser and restored later, and undo steps back through your edits.
Who this is for
Web developers checking a template before it goes into a build, email and CRM users testing merge fields, and students learning the difference between Mustache and Handlebars.
Limits
Custom JavaScript helpers registered in your own code are not run, for safety; calls to them show an unknown helper error. Chained {{else if}} blocks, Mustache set-delimiter tags, partial blocks and inline partials are not supported; each stops the render with an error naming its line, so nest a second if inside the else instead of writing else if. Whitespace control marks with tildes are accepted, but the spaces and line breaks they would remove are kept. Decorators are not supported. HTML escaping covers the seven characters Handlebars escapes. Output from this engine can differ in small whitespace details from the real libraries, so test the final template in your own build. This is not security advice about rendering untrusted templates on a server.
Worked example
Invoice example: INV-1042 for Maya Patel, Brightline Studio; rows 1 Logo design 450.00 and 2 Business cards (box) 3 x 28.50 = 85.50; footer "Thank you, MAYA PATEL."
Quick facts
- Category: Developer & Data
- Works in your browser, no sign-up, no upload.
- Your input stays on your device.
- Available in English.
- Content last reviewed:
- Official source: Mustache(5) manual and spec; Handlebars language guide (built-in helpers, blocks, partials)
Frequently asked questions
Is this the real Handlebars library?
No. It is a small engine written for this page that follows the Mustache manual and the Handlebars language guide for variables, sections, blocks, partials and the listed helpers. It never evaluates code, and results can differ in small details from the official libraries.
Which helpers can I use?
eq, ne, gt, lt, gte, lte, and, or, not, upper, lower, capitalize, trim, json, join, length, default, concat, lookup, add, subtract, multiply, divide, fixed and date, plus the block helpers if, unless, each and with. Helpers can be nested as sub-expressions in brackets.
Why does a name show as empty inside an each block?
In Handlebars mode a name is looked up only in the current item. Use ../name for the parent context or @root.name for the top of the data. Mustache mode walks up the context stack automatically.
How do partials work here?
Add a partial in the Partials tab, give it a name without spaces and write its template. Call it with {{> name}}, optionally with a context such as {{> name customer}}. A missing partial is reported as an error with its line.
Can I register my own helper?
No. Custom JavaScript helpers are not run on this page. Use the built-in helpers, or pre-compute the value in your JSON data while testing the layout.
Does the HTML preview run scripts?
No. The preview is a sandboxed frame with scripts turned off, so a script tag in the output is shown but never executed.
