Closed SeanFarrow closed 1 year ago
I can't seem to get this to work either. Example:
Template
{{String.Split "a;b;c" ";"}}
{{#each (String.Split "a;b;c" ";")}}
{{@Key}}:{{@Index}}:{{this}}
{{/each}}
Result
["a","b","c"]
Length:0:13
@SeanFarrow and @kspearrin
Did you check the unit test?
@StefH Yes, I can get String.Split
to work on its own, but when pairing the result with #each
to iterate over the array, I get the weird behavior shown above, showing the length of the array.
Currently, the result from that string.split is a json-array. Not a real object array which can be used in each-loop.
I can't remember why I build this code to behave like this... Maybe a different usecase....
I need to think on this...
In the meantime, I was able to fix this by just overloading the exiting String.Split helper with my own custom one:
context.RegisterHelper("String.Split", (context, arguments) =>
{
var value = arguments[0] as string;
var separator = arguments[1] as string;
return value.Split(separator);
});
@kspearrin
Preview version 2.3.8-ci-16673.
should solve this. Can you test ?
(https://github.com/Handlebars-Net/Handlebars.Net.Helpers/wiki/MyGet)
@kspearrin Can you test this preview version?
(If it's ok, then I can merge PR to master and take a look at your PR)
@StefH Confirmed that it works.
I am trying to use the String.Split helper in an #each expression, but can't seem to find the correct syntax.
Does anyone have any examples?
Thanks, Sean.