diff --git a/src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.m b/src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.m index 5776d67..cd59c6b 100644 --- a/src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.m +++ b/src/handlebars-objc/helpers/HBBuiltinHelpersRegistry.m @@ -110,7 +110,13 @@ + (void) registerEachHelper { HBHelperBlock eachBlock = ^(HBHelperCallingInfo* callingInfo) { - id expression = callingInfo[0]; + id expression = nil; + if ([callingInfo.positionalParameters count] > 0) { + expression = callingInfo[0]; + } else { + expression = callingInfo.context; + } + HBDataContext* currentData = callingInfo.data; if (expression && [HBHelperUtils isEnumerableByIndex:expression]) { diff --git a/src/handlebars-objcTests/HBTestBuiltinBlockHelpers.m b/src/handlebars-objcTests/HBTestBuiltinBlockHelpers.m index 90c6995..d848ea1 100644 --- a/src/handlebars-objcTests/HBTestBuiltinBlockHelpers.m +++ b/src/handlebars-objcTests/HBTestBuiltinBlockHelpers.m @@ -192,6 +192,16 @@ - (void) testEachWithNestedAtLast XCTAssert(!error, @"evaluation should not generate an error"); } +// each on implicit context +- (void) testEachOnImplicitContext +{ + NSError* error = nil; + id string = @"{{#each}}{{text}}! {{/each}}cruel world!"; + id hash = @[ @{ @"text": @"goodbye" } ,@{ @"text": @"Goodbye" } ,@{ @"text": @"GOODBYE" } ]; + XCTAssertEqualObjects([HBHandlebars renderTemplateString:string withContext:hash error:&error], + @"goodbye! Goodbye! GOODBYE! cruel world!"); + XCTAssert(!error, @"evaluation should not generate an error"); +} // #log - (void) testLog