public
Last active

  • Download Gist
gistfile1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
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.

Props on the proposal, found this from stack overflow.

Here is a reference to the proposal on the mustache spec issues list: https://github.com/mustache/spec/issues/38

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.