Created
February 17, 2012 18:16
-
-
Save spullara/1854699 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Props on the proposal, found this from stack overflow.