Skip to content

Instantly share code, notes, and snippets.

@spullara
Created February 17, 2012 18:16
Show Gist options
  • Save spullara/1854699 to your computer and use it in GitHub Desktop.
Save spullara/1854699 to your computer and use it in GitHub Desktop.
My proposal is a declarative syntax for defining replaceable blocks, very much akin to the
way this is done in Django and some other templating systems. Here is simple example:
super.mustache:
<html>
<head><title>{{$title}}Default title{{/title}}</title></head>
<body>
{{>navigation}}
<div class="content">
{{$content}}Default content of the page{{/content}}
</div>
{{>footer}}
</body>
</html>
sub.mustache:
{{<super}}
{{$title}}Profile of {{username}} | Twitter{{/title}}
{{$content}}
Here is {{username}}'s profile page
{{/content}}
{{/super}}```
the virtual mustache template that is rendered:
<html>
<head><title>Profile of {{username}} | Twitter</title></head>
<body>
{{>navigation}}
<div class="content">
Here is {{username}}'s profile page</div>
{{>footer}}
</body>
</html>
There are many ways that people have tried to workaround this limitation including:
- rendering sub templates into {{{content}}} values
- using javascript to render sections separate and splatting them into the DOM
- reproducing the bones in each sub page through a bunch of partials
- creating massive switch statements using sections
All of these allow business logic and code to creep into the template. My proposal
to maintain the declarative nature of mustache by adding this very powerful
inheritance feature.
@devinrhode2
Copy link

Props on the proposal, found this from stack overflow.

@spullara
Copy link
Author

Here is a reference to the proposal on the mustache spec issues list: mustache/spec#38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment