Reputation: 19445
I have an object 'obj' that have a numeric value 'count'. I want to add "'count'" images of star to the page. something like:
{{#for i=0;i<count;++i}}
<img src="/star.png" style="width: 16px; height: 16px" />
{{/for}}
I know this is not valid, but how can I get that behavior?
Upvotes: 1
Views: 268
Reputation: 1612
I believe I found how to do it: https://github.com/meteor/meteor/blob/8ac310b9db204ccb74039b691aae6962d5799fe9/packages/blaze/builtins.js#L75
I think you need to extend Blaze object Blaze.For
but I don't think you can evaluate i<count
and i++
.
A possible implementation by extending Blaze:
{{#range 0 count 1}}
{{/range}}
Lazy man implementation:
Template.yourTemplate.helpers({
range : function( start , end , inc ){
return _.range( start , end , inc );
}
})
Still Lazy:
{{#with range 0 count 1}}
{{/with}}
If you want to the range functionality to Blaze you've to handle a lot.
Upvotes: 3