Handlebars showing only first three items

强颜欢笑 提交于 2019-12-05 21:33:24

you are going to need to use a Handlebar helper, handle bars does not do this type of conditional checking.

    Handlebars.registerHelper('arrayCheck', function (newsArray) {
        //Logic
    });
sebfitz

I have modified your Handlebar to support a range you can define. In example you want to display 4 items but want to begin with the second one. Here you go:

/*
 * Item helper.
 *
 * @return n elements
 */
Handlebars.registerHelper('listItem', function (from, to, context, options){
    var item = "";
    for (var i = from, j = to; i < j; i++) {
        item = item + options.fn(context[i]);
    }
    return item;
});

Then just use the handlebar like this:

{{#listItem 2 6 articles}}
    {{> article }}
{{/listItem}}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!