canjs / can-stache

Live binding handlebars templates
https://canjs.com/doc/can-stache.html
MIT License
10 stars 13 forks source link

Add for(integerVal) counting loops #709

Closed JaneOri closed 4 years ago

JaneOri commented 5 years ago

Hey fam!

This adds integer count loops to output based on numbers. Most frequently for me I've needed this for heavy visual builds.

    var template = stache("<div>{{#for(integerValue)}}[{{scope.index}}]{{/for}}</div>");
    var frag = template({
        integerValue: 3
    });
    // frag.firstChild.innerHTML === "[0][1][2]"

I queried about this years ago, wish I would have taken a look sooner since it was so easy to implement.

I understand if you decide against the feature, but I'd really like to have it and would be happy to discuss further if needed!

Hope you're all well! //James

justinbmeyer commented 5 years ago

Yeah, I think this is a great feature! I added notes for a few cleanup items. Thanks @James0x57 !

JaneOri commented 5 years ago

Hey Justin! I've Addressed each item

Here's what the updated expression part in the docs looks like locally now: image