Skip to content

Instantly share code, notes, and snippets.

@groue
Created September 23, 2012 12:21
Show Gist options
  • Save groue/3770302 to your computer and use it in GitHub Desktop.
Save groue/3770302 to your computer and use it in GitHub Desktop.
GRMustache: reuse common layout templates
{{<layout}}
{{$page_title}}
{{title}}
{{/page_title}}
{{$page_content}}
<p>{{text}}</p>
<p>by {{author}}</p>
{{/page_content}}
{{/layout}}
<h1>{{$page_title}}Default title{{/page_title}}</h1>
<html>
<head>
<title>{{$page_title}}Default title{{/page_title}}</title>
</head>
<body>
{{>header}}
{{$page_content}}Default content{{/page_content}}
</body>
</html>
id article = @{
@"title": @"Layouts are awesome",
@"author": @"John Doe",
@"text": @"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
};
NSString *rendering = [GRMustacheTemplate renderObject:article
fromResource:@"article"
bundle:nil
error:NULL];
<html>
<head>
<title>
Layouts are awesome
</title>
</head>
<body>
<h1>
Layouts are awesome
</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>by John Doe</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment