I am using Handlebars for java from : https://github.com/jknack/handlebars.java I have a list of CustomObject and a template file template.hbs. I'm able to iterate over this list by using handle bars {{#each customList}} block.
Now I want to iterate only through even indexed objects in my customList.
Server side :
handlebars.registerHelper("even", new Helper<List<?>>() {
@Override
public Object apply(List<?> list, Options options)
throws IOException {
if(list!=null && list.size()>1) {
for(int index=0;index<list.size();index++) {
if((index+1) % 2 != 0) {
options.fn(list.remove(index));
}
}
}
return list;
part of Template.hbs:
{{#even customList}}
{{customProperty1}}
{{/even}}
But this doesn't iterate my customList instead it just prints my list as string.