What the Glimmer JS Formatter does
The Glimmer JS Formatter formats Glimmer and Handlebars templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Glimmer/Handlebars templates used by Ember.
Glimmer JS Formatter examples
The built-in sample
Input
<div class="card {{if @active 'on'}}">
{{#if @user}}
<p>{{@user.name}}</p>
{{else}}
<p>Guest</p>
{{/if}}
</div>Output
<div class="card {{if @active 'on'}}">
{{#if @user}}
<p>{{@user.name}}</p>
{{else}}
<p>Guest</p>
{{/if}}
</div>This is the input that the Load sample button fills in.
Block helpers, component arguments and modifiers
Input
{{#each @items as |item|}}
<Item @value={{item}} class='row'/>
{{/each}}
<Input @value={{this.q}} {{on "input" this.update}}/>Output
{{#each @items as |item|}}
<Item @value={{item}} class="row" />
{{/each}}
<Input @value={{this.q}} {{on "input" this.update}} />The contents of the each block are indented, the attribute value gets double quotes and a space is added before the self-closing slash.
Each output was produced by running this tool on the input above it.
How it works
The code is parsed with Prettier's glimmer parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.
Details and limits
- Handles the template syntax used by Ember and Glimmer:
{{#if}}and{{#each}}blocks, angle-bracket components,@argumentsand element modifiers. - String literals inside curly expressions get double quotes, except inside an attribute value that is itself double-quoted, where single quotes are kept.
- Comments written as
{{!-- --}}may be shortened to{{! }}when they do not contain}}. - A template embedded in a JavaScript file with
hbsor a<template>tag is not extracted; paste the template on its own.
Questions
Is my data uploaded when I use Glimmer JS Formatter?
No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.
What does Glimmer JS Formatter do?
The Glimmer JS Formatter formats Glimmer and Handlebars templates with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports Glimmer/Handlebars templates used by Ember.
How does Glimmer JS Formatter work?
The code is parsed with Prettier's glimmer parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.
Are there any limits I should know about?
Handles the template syntax used by Ember and Glimmer: {{#if}} and {{#each}} blocks, angle-bracket components, @arguments and element modifiers. String literals inside curly expressions get double quotes, except inside an attribute value that is itself double-quoted, where single quotes are kept.
Is there a size limit?
There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.
Does it work on phones, and is it free?
Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.