Syntax for calling helper function from {{#each ..}}
-
I have a helper function which returns an array. This function cannot be caller directly in a {{#each }} clause like this:
{{#each getFlattenedControlpointArray}}
In order to actually call the function I have to fake a parameter like this
{{#each (getFlattenedControlpointArray 1)}}
Is this a bug or have I misunderstood something?
-
hi!
This function cannot be caller directly in a {{#each }} clause like this:
{{#each getFlattenedControlpointArray}}yes, this is expected, you are passing here a function to the each, which expects an array, if we translate this to javascript execution it will look like this
// it won't do nothing because it expects array to iterate each(function getFlattenedControlpointArray () {})
In order to actually call the function I have to fake a parameter like this
{{#each (getFlattenedControlpointArray 1)}}in this case your are executing the
getFlattenedControlpointArray
function the(
and)
are needed for handlebars to execute functions/helpers when we are in the execution of another helper (the#each
)if we translate this to javascript execution it will look like this:
// this time it works because it is executing the `getFlattenedControlpointArray` and passing the return to the each each(getFlattenedControlpointArray(1))
FYI you don't need the pass a fake parameter, it also works with this
{{#each (getFlattenedControlpointArray)}}
https://playground.jsreport.net/w/anon/tDUXYi84
Is this a bug or have I misunderstood something?
it is how the handlebars syntax works, in case you need here is link to handlebars docs that explains this
hope this makes things more clear to you
-
Of course, I should have thought of that.
Thank you for explaining.