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

getting second parameter in a filter #62

Closed angelochen960 closed 11 years ago

angelochen960 commented 11 years ago

Hi, I pass a second parameter from my filter 'txt', it's 10, but in the txt_blk, it's always a [NSNull null] while the first parameter is valid, what am I missing here?

Thanks,

id txt_blk = ^id(NSArray *arguments) {
       // NSInteger len = [[arguments objectAtIndex:1] intValue];  // always [NSNull null]
        return [arguments objectAtIndex:0];
    };

id data = @{ @"name" :@"sample", @"txt": [GRMustacheFilter variadicFilterWithBlock:txt_blk]};

    NSString *rendering = [GRMustacheTemplate renderObject:data fromString:@"hello {{txt(name,10)}}" error:NULL];
    NSLog(@"result : %@", rendering);
groue commented 11 years ago

You get null for the 10 parameter because 10 is interpreted as a key, that resolves to nil, and not as a literal number. GRMustache has no support for integer nor string literals.

angelochen960 commented 11 years ago

i see, it will be nice to have that.

groue commented 11 years ago

Yes, literals look like a nice addition. However, they bring their own set of difficulties and inconsistencies that I don't plan to solve right now. See #54 for the full discussion, if you are interested.