The PHP Code:
$helpers = array(
'myeach' => function ($context, $options) {
$ret = '';
$theArray = json_decode($context, true);
if(!is_array($theArray)) {
return '';
}
foreach ($theArray as $i) {
$ret .= $options['fn']($i);
}
return $ret;
},
);
$options = array(
'flags' => LightnCandy::FLAG_ERROR_LOG | LightnCandy::FLAG_STANDALONEPHP | LightnCandy::FLAG_HANDLEBARSJS | LightnCandy::FLAG_ADVARNAME | LightnCandy::FLAG_SPVARS | LightnCandy::FLAG_PARENT | LightnCandy::FLAG_JSTRUE | LightnCandy::FLAG_JSOBJECT,
'helpers' => $helpers
);
$php = LightnCandy::compile($template, $options);
$renderer = LightnCandy::prepare($php);
$handlebarsOutput = $renderer($config);
Template:
{{#myeach '[{"a":"ayy", "b":"bee"},{"a":"zzz", "b":"ccc"}]' as | newContext index | }}
Foo {{newContext.a}} {{index}}
{{/myeach}}
The Issue:
As in the example I have a custom each helper. When I attempt to use the as | value index| syntax as described in handlebars documentation it does not work. this will return the object that was pulled from the JSON okay, but newContext and index print nothing. Such that the rendered output is simply Foo Foo
Do I need additional flags to enable this? What am I doing wrong here?
The PHP Code:
Template:
The Issue:
As in the example I have a custom each helper. When I attempt to use the
as | value index|syntax as described in handlebars documentation it does not work.thiswill return the object that was pulled from the JSON okay, butnewContextandindexprint nothing. Such that the rendered output is simplyFoo FooDo I need additional flags to enable this? What am I doing wrong here?