Closed angelochen960 closed 11 years ago
Hi @angelochen960 !
Sure it is possible.
You have basically two options:
1.Keep your template as is, and write your custom filter (look at https://github.com/groue/GRMustache/blob/master/Guides/filters.md)
Tell me if you are experiencing any difficulty.
thanks for the quick response, I have something very similar to this:
NSNumberFormatter *percentFormatter = [NSNumberFormatter new];
percentFormatter.numberStyle = NSNumberFormatterPercentStyle;
id data = @{
@"x": @(0.5),
@"percent": percentFormatter,
};
NSString *rendering = [GRMustacheTemplate renderObject:data
fromResource:@"Document"
bundle:nil
error:NULL];
can it to be modify to have '##' if the x is 0.0? Thanks
following works:
@"amt": [GRMustacheFilter filterWithBlock:^id(id object) {
NSNumberFormatter *numberFormatter = [NSNumberFormatter new];
numberFormatter.numberStyle = NSNumberFormatterDecimalStyle;
numberFormatter.minimumFractionDigits =2;
NSLog(@"obj is %@", object);
if (object != [NSNull null])
return [numberFormatter stringFromNumber:object];
else
return @"###";
}]
Hi, say I have this template: {{reference}} {{amt(debit)}} {{amt(credit)}} {{amt(balance)}}
in every line, either debit or credit will be null, so it does not render, I'd like to render a space of 10 if it is null so that the report looks aligned in proper columns, possible?
Angelo