mardi 3 février 2015

Ember.js - conditionally display template content based on current model item index

I have an Ember.js app that requires me to render content in groups of 6. For example, I have a model that contains 18 'activities.' I need to group the activities in sets of six, so I'll have three groupings of six each. I know I can't use non-boolean conditionals in Handlebars, so does anyone have an idea on how to best implement the following concept?



<script type="text/x-handlerbars" data-template-name="categories">
{{#each activity in parentController.activity}}
// For every sixth item, start a new grouping
{{#if activity.index() % 6 == 0}}
<div class="activityBlock">
// Render views 1 - 6 the first time, 7 - 12 the second time, and 13 - 18 the third time
{{view "activity"}}
</div>
{{/if}}
{{/each}}
</script>

<script type="text/x-handlebars" data-template-name="activity">
{{item.title}}
</script>

Aucun commentaire:

Enregistrer un commentaire