I'm using Swig as a template engine for Express.js and I found no way to make a for loop with a variable like so:
for(var i=0; i<100; i++){
//whatever
}
Is this even possible?
As posted on your github issue for the same question, loops like this don't exist in Swig. You can iterate over actual objects and arrays, however. (See for-tag documentation).
Otherwise, you could create a range helper, as discussed here
swig.setDefaults({ locals: {
range: function (start, len) {
return (new Array(len)).join().split(',').map(function (n, idx) { return idx + start; });
}
}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With