mustache/spec — pull request #75 by jazzdan (2014-04-14 21:07:39+00:00)
Title: Add template inheritance spec

This adds a specification for [hogan.js](https://github.com/twitter/hogan.js) style template inheritance. As of time of writing, three mustache implementations are 100% compatible with this implementation:

* [hogan.js](https://github.com/twitter/hogan.js)
* [mustache.php](https://github.com/bobthecow/mustache.php/pull/198)
* [mustache.java](https://github.com/spullara/mustache.java)

Here's how it works:

```HTML+Django
{{! header.mustache }}

{{$title}}Default title{{/title}}

```
```HTML+Django
{{! base.mustache }}

{{$header}}{{/header}}
{{$content}}{{/content}}

```
```HTML+Django
{{! mypage.mustache }}
{{Hello world

{{/content}}
{{/base}}
```

Rendering mypage.mustache would output:
```HTML

My page title

Hello world

```

A full specification can be seen below.

At @Etsy, much like @Twitter (see #38), we often want to have one template where we maintain the "bones" of the page and each real page on the site merely replaces sections of that page with appropriate content. A simple example of this can be seen above, where a page can grab base, getting all of our analytics scripts and other markup that every page needs, while retaining the ability to swap in a completely different header. Alternatives, such as copying the bones to every top level template, or simulating this behavior with a multi-step mustache render on the server, are not ideal.

Etsy is in the process of rolling out the new version of mustache.php that supports template inheritance to our production cluster after testing this implementation extensively. Hogan.js and mustache.java are both being used in production at Twitter.

Many thanks to @dtb, @mdg, @bobthecow for their assistance. Special thanks to @spullara for quickly making mustache.java compatible with this spec.