Documentation of rendering objects: https://github.com/groue/GRMustache/blob/master/Guides/rendering_objects.md
Created
September 22, 2012 11:03
-
-
Save groue/3765844 to your computer and use it in GitHub Desktop.
GRMustache: variable tag that expand into a template string
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
{{#movie}} | |
{{link}} | |
{{#director}} | |
by {{link}} | |
{{/director}} | |
{{/movie}} |
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
id data = @{ | |
@"movie": @{ | |
@"url": @"/movies/123", | |
@"title": @"Citizen Kane", | |
@"link": [GRMustache renderingObjectWithBlock:^NSString *(GRMustacheTag *tag, GRMustacheContext *context, BOOL *HTMLSafe, NSError **error) { | |
NSString *templateString = @"<a href=\"{{url}}\">{{title}}</a>"; | |
GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL]; | |
return [template renderContentWithContext:context HTMLSafe:HTMLSafe error:error]; | |
}], | |
@"director": @{ | |
@"url": @"/people/321", | |
@"firstName": @"Orson", | |
@"lastName": @"Welles", | |
@"link": [GRMustache renderingObjectWithBlock:^NSString *(GRMustacheTag *tag, GRMustacheContext *context, BOOL *HTMLSafe, NSError **error) { | |
NSString *templateString = @"<a href=\"{{url}}\">{{firstName}} {{lastName}}</a>"; | |
GRMustacheTemplate *template = [GRMustacheTemplate templateFromString:templateString error:NULL]; | |
return [template renderContentWithContext:context HTMLSafe:HTMLSafe error:error]; | |
}], | |
} | |
} | |
} | |
NSString *rendering = [GRMustacheTemplate renderObject:data | |
fromResource:@"Document" | |
bundle:nil | |
error:NULL]; |
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
<a href="/movies/123">Citizen Kane</a> | |
by <a href="/people/321">Orson Welles</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment