Reputation: 45295
I have a template:
<template name="week_list">
{{#each days}}
{{day_of_month this}} <br />
{{#each action_log_on_day this}}
{{Name}} : {{Score}} <br />
{{/each}}
{{/each}}
</template>
Is there a way to sum all the 'Score'-s in the template or I need to create a separate js-function (with own mongo query) for it ?
Upvotes: 1
Views: 2135
Reputation: 878
You will need to create a separate function for that because the only purpose of templates in meteor is to display things, you're not able to implement any logic in templates at all. Your function might look similar to this:
var sum = 0;
Documents.find({...}).forEach(function (doc) { sum += doc.Score; });
return sum;
Upvotes: 3