groue / GRMustache

Flexible and production-ready Mustache templates for MacOS Cocoa and iOS
http://mustache.github.com/
MIT License
1.44k stars 190 forks source link

Documentation lacks of precision in filter definition #59

Closed spacreau closed 11 years ago

spacreau commented 11 years ago

Need to render object with filters defined separately with the method :

like this

GRMustacheTemplate template = [GRMustacheTemplate templateFromResource:@"reportTemplate" bundle:nil error:NULL]; NSString rendering = [template renderObject:@{@"alert": @{ @"label": @"label.screen.reporting.content.label.alerts", @"allalerts": allalerts, } } withFilters:@{@"dateFormat" : [GRMustacheFilter filterWithBlock:^id(id object) { return [self.dateFormatter stringFromDate:object];}] } ];

{{ dateFormat(aircraftGPSPoint.timestamp) }}

else I never manage to render object with a filter

groue commented 11 years ago

Hi, @spacreau

If you really need to provide data and filters in separate containers, here is a way to do it:

// One container for data...
id data = @{@"alert": @{ @"label": @"label.screen.reporting.content.label.alerts", @"allalerts": allalerts, } };

// A second container for filters (NSDateFormatter is already a filter since v6.4):
id filters = @{@"dateFormat" : self.dateFormatter };

// Rendering
NSString *rendering = [template renderObjectsFromArray:@[filters, data] error:NULL];
groue commented 11 years ago

I do not understand the title of the issue: "Documentation lacks of precision in filter definition" ?

groue commented 11 years ago

The more I think of it, the more I believe you are using an old version of GRMustache. The documentation for it is in the distribution itself (check the Guides folder). This website shows the documentation for the latest version of the library. If this does not answer your question, feel free to reopen this issue.