Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom each does not support as | a index | syntax #371

Open
willdkp opened this issue Mar 22, 2024 · 0 comments
Open

Custom each does not support as | a index | syntax #371

willdkp opened this issue Mar 22, 2024 · 0 comments

Comments

@willdkp
Copy link

willdkp commented Mar 22, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant