Skip to content
html needs a coat
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Coat Templating Language

Coat templates attempt to provide a powerful syntax sharing similarities to handlebars and swig. Each coat file describes an element that can be rendered, composed, imported, and/or extended.

Langage Documentation


Variables use single mustache syntax. Variables can be selected using dot seperated object paths (eg. {}). Arrays can be accessed using dot syntax as well (ed. {items.2.title})



Filters can be used to manipulate variables. They can be chained using the pipe | character (eg. { user.names|first|capitalize }). Filters are plugin based, described in more detail in addFilter.



Helpers are logical blocks in code. Inside they create a new scoped variable called this that references the current iterator and loop that references helper variables. Helpers are plugin based, described in more detail in addHelper.

  {#each cast}
    <li>{loop.index} - {}</li>


Directives modify how modules are processed by the precompiler.

{!import link './link.coat'}
<!-- import can overwrite built-in elements -->
<link href="#/123">123ABC</link>

Yield Point

The yield keyword defines a yield point in a template module. Each template can define one yield point using the !yield directive. This can be used to fill with content or further composed with other modules.

<!-- link.coat -->
<a href="{href}" class="link">{!yield}</a>

<!-- page.coat -->
{!import link './link.coat'}
<link href="#/abc">ABC</link>
<!-- output.html -->
<a href="#/abc" class="link">ABC</a>

Yield Block

Yield Blocks are used to define multiple yield points inside of a template. They can be extended and modified using the !extends directive. Blocks are similar to using the !import directive to import and use another module, but allows for more elegant module composition and inheritance.

<!-- card.coat -->
<div class="card">


<!-- page.coat -->
{!import card './card.coat'}

  <card-header>Hello Beautiful World</card-header>
  <p>Lorem ipsum Commodo mollit amet ut dolore ullamco ad.</p>
<!-- output.html -->
<div class="card">
    <h3>Hello Beautiful World</h3>
  <p>Lorem ipsum Commodo mollit amet ut dolore ullamco ad.</p>

Module Inheritance

Modules can be extended using the !extends directive, this allows you to reuse another modules structure and redefine specific yield blocks.

<!-- media-card.coat -->
{!extends "./card.coat"}

    <img src="{src}" alt="{title}" />

<!-- page.coat -->
{!import mcard './media-card.coat'}

<mcard type="image">
    <mcard-header src="" title="Card #4">Card #4</mcard-header>
    Lorem ipsum Aliqua in ea amet anim sed deserunt.
<!-- output.html -->
<div class="card" data-type="image">
  <header class="card-header">
    <img src="" alt="Card #4" />
    <h1>Card #4</h1>
  <div class="card-content">Lorem ipsum Aliqua in ea amet anim sed deserunt.</div>

Javascript API


The coat module includes a precompiler and a renderer, the renderer can be included seperated using the coat-runtime module.

var Coat = require('coat');


Precompiles a coat template into a javascript function. The function accepts a JSON object argument and outputs a html string.

var PageTemplate = Coat.compile('./page.coat');


Coat.addFilter('nth', function(contents, n) {
    return contents[n];

Coat.addFilter('first', function(contents) {
    return contents[0];


Coat.addHelper('nth', function(contents, n) {
    return contents[n];
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.