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

Helper cannot return Array or Object #1229

Closed
toksea opened this issue May 31, 2016 · 2 comments
Closed

Helper cannot return Array or Object #1229

toksea opened this issue May 31, 2016 · 2 comments

Comments

@toksea
Copy link

toksea commented May 31, 2016

Hi! It seems that return value of custom helpers will force cast to string.

e.g.

Handlebars.registerHelper('testArray',function(object) {
    return [1,2,3];
});

{{#testArray}}loop{{/testArray}}

// will output
1,2,3

Can I return Array or Object from helpers?

@nknapp
Copy link
Collaborator

nknapp commented May 31, 2016

You can use your helper as argument to the {{#each}}-helper in order to iterate the array. Try this template:

{{#each (testArray)}}
    {{.}}.loop
{{/each}}

@toksea
Copy link
Author

toksea commented Jun 1, 2016

@nknapp Thank you! It works!

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

2 participants