← backEmblem.js | |
|---|---|
Syntax | |
TagsYou can wrap content within an html5 element by just writing the element name at the beginning of a line. This is supported for all valid html5 tags (list here.) To use a non-html5 tag, just start the line with | h1 Welcome to Emblem
%blink buy it on Kozmo.com
<h1>Welcome to Emblem</h1> <blink>buy it on Kozmo.com</blink> |
Indentation WrappingTo wrap one element in another, just indent and place the element below. | footer ul li Hello li Goodbye <footer> <ul> <li>Hello</li> <li>Goodbye</li> </ul> </footer> |
CSS ClassesCSS classes can added to elements by using a ( You can chain multiple class names. | .title Title h1.logo Law Blog button.btn.btn-large Submit <div class="title">Title</div> <h1 class="logo">Law Blog</h1> <button class="btn btn-large">Submit</button> |
IDsElement IDs can be added to elements by using | #page-content Content span#name Bob Lablah <div id="page-content">Content</div> <span id="name">Bob Lablah</span> |
HTML AttributesHTML attributes can be added right after the element, using HTML attributes can also have mustaches embedded in them, though make sure to use the | button.close data-dismiss="modal" x / For Vanilla Handlebars mode only button class="large {{foo}}" x / For Ember Handlebars button class="large {{unbound foo}}" x / Shorthand for Ember button class=foo! x <button class="close" data-dismiss="dropdown">x</button> <button class="large {{foo}}">x</button> <button class="large {{unbound foo}}">x</button> <button class="{{unbound foo}}">x</button> |
CommentsStart a line with Multiline comments are supported by indenting your comment underneath. | / Some comment / A long long multiline comment |
Plain TextTo output content without an element wrapper, start the line with pipe Multiline plaintext content is supported by indenting underneath the tag or Plain text can include handlebars output tags Block helpers within text blocks can also be used if you’re using the Use an apostrophe | | Some content p | Lorem #{linkTo 'something' | ipsum} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. span.name Your name is {{name}} and my name is #{author} span ' Trailing space Some content <p> Lorem {{#linkTo something}}ipsum{{/linkTo}} dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p> <span class="name">Your name is {{name}} and my name is {{author}}</span> <span>Trailing space </span> |
Handlebars ExpressionsTo output a handlebars expression, use NOTE: You have the option to omit the | h1 = name p = intro = highlight name <h1>{{name}}</h1> <p> {{intro}} {{hightlight name}} </p> |
Unescaped ExpressionsBy default Handlebars html escapes output from expressions. To include html without escaping, use | body
== outlet
<body> {{{outlet}}} </body> |
Handlebars Block HelpersHandlebars block statements follow a syntax similar to HTML5 elements, in that indented content on the lines below get wrapped in the block form of the helper. To use a block helper with the same name as an HTML5 element, you can explicitly use a handlebars block helper by starting the line with Block helpers with only text content can be succinctly written on a single line using a | ul each person in people li = person linkTo "home" | Link Text list nav id="nav-bar" class="top" a href="url" = title = strong = something if something p Something! else p Something else! <ul> {{#each person in people}} <li>{{person}}</li> {{/each}} </ul> {{#linkTo "home"}} Link Text {{/linkTo}} {{list nav id="nav-bar" class="top"}} <a href="{{url}}">{{title}}</a> {{/list}} {{#strong}} {{something}} {{/strong}} {{#if something}} <p>Something!</p> {{else}} <p>Something else!</p> {{/if}} |
Condensed Nesting with Colon Separator (NEW)You can condense nested HTML or block mustache content into a single line by using Whatever comes after a statement-terminating This should come in handy for scaffolding frameworks like Twitter Bootstrap (the first part of the example on the right is Bootstrap scaffolding code). | #content-frame: .container: .row: .span4: render "sidebar" .span8: render "main" footer: ul.menu-items: each menu_items: li: a.menu-link href=url: link_text <div id="content-frame"> <div class="container"> <div class="row"> <div class="span4"> {{render "sidebar"}} </div> <div class="span8"> {{render "main"}} </div> </div> </div> </div> <footer> <ul class="menu-items"> {{#each menu_items}} <li> <!-- of course, in an Ember.js context, href will be set via a bindAttr --> <a class="menu-link" href="{{url}}">{{link_text}}</a> </li> {{/each}} </ul> </footer> |
ViewsEmber.js onlyYou can quickly and easily include an Ember.js view by starting a line with a capitalized letter. This will automatically wrap the line with a | .field Ember.TextField valueBinding="firstName" <div class="field"> {{view Ember.TextField valueBinding="firstName"}} </div> |
bindAttr ShorthandEmber.js onlyEmblem.js makes binding expression attributes (via | img src=logoUrl alt="Logo" div class=condition:whenTrue:whenFalse div class={ condition1:whenTrue:whenFalse condition2:whenTrue:whenFalse } <img {{bindAttr src="logoUrl"}} alt="Logo"> <div {{bindAttr class="condition:whenTrue:whenFalse"}}></div> <div {{bindAttr class="condition1:whenTrue:whenFalse condition2:whenTrue:whenFalse"}}></div> |
Action / Events ShorthandEmber.js onlyLike with HTML5 elements, Emblem is aware of common Ember action names, such as | a click="toggleHeader" x a click="toggleHeader this" x form submit="submitTheForm foo" p Hello <a {{action toggleHeader on="click"}}>x</a> <a {{action toggleHeader this on="click"}}>x</a> <form {{action submitTheForm foo on="submit"}}><p>Hello</p></form> |
Explicit Attribute ExpressionsEmber.js onlyTo use expressions within the element attributes (often used in Ember with Multiple attribute expressions are also supported. | button{action "delete"} Delete img{bindAttr src="logoUrl"} alt="logo" a{bindAttr class="isActive"}{action 'toggleHeader'} x <button {{action "delete"}}>Delete</button> <img {{bindAttr src="logoUrl"}} alt="logo"> <a {{bindAttr class="isActive"}} {{action "toggleHeader"}}>x</a> |
In-Tag MustacheOccasionally, you’ll want to put mustache content inside the opening tag of an HTML element. You can do this by immediately following the tag content with curly braces. Note: instead of using this for Ember’s | span.some-class{ someHelper } Hello
<span class="some-class" someHelperOutput="foo">Hello</span> |
Vanilla Handlebars PartialsTo invoke partials with non-Emberized Handlebars, you can use the Note that you’ll never really use this for Ember apps; rather, in those cases, you’d use the Also note that there’s no good way to precompile partials other than to precompile them as templates and then run If you’re not precompiling, and you want to directly register an Emblem template, you can use | > partialName p Check out this partial: #{> partialName} > partialName foo {{>partialName}}
<p>Check out this partial: {{>partialName}}</p>
{{>partialName foo}}
|
Anything wrong or missing here?These docs are open source, so help us tweak and refine them! If you’re feeling particularly lazy and want to just report an error, Submit a docs issue for some clarification on how Emblem.js can be used. | |
To see some other really cool stuff that Emblem is capable of, see the Idioms docs. |