Skip to content

@groue /_documentation.md
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
GRMustache: variadic filters
{{#object1}}
{{ dateFormat(date, format) }}
{{/object1}}
{{#object2}}
{{ dateFormat(date) }}
{{/object2}}
id filters = @{
@"dateFormat": [GRMustacheFilter variadicFilterWithBlock:^id(NSArray *arguments) {
// first argument is date
NSDate *date = [arguments objectAtIndex:0];
// second (optional) argument is format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
if (arguments.count > 1)
dateFormatter.format = [arguments objectAtIndex:1];
else
dateFormatter.format = @"yyyy-MM-dd";
// compute the result
return [dateFormatter stringFromDate:date];
}]
};
id data = @{
@"object1": @{
@"format": @"yyyy-MM-dd 'at' HH:mm",
@"date": [NSDate date]
},
@"object2": @{
@"date": [NSDate date]
}
};
NSString *rendering = [GRMustacheTemplate renderObject:data
withFilters:filters
fromResource:@"base"
bundle:nil
error:NULL];
2012-10-20 at 15:05
2012-10-20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.