I have the following template code:
<template name="dashboard">
<div class="content-container-with-sidebar clearfix">
<div class="dashboard-container">
{{#if Template.subscriptionsReady}}
<div id=masonry-grid class="masonry-grid clearfix">
{{> timePieChartCard}}
{{> expensePieChartCard}}
{{> HighlightsCard}}
{{> initializeMasonry}}
</div>
{{/if}}
</div>
</div>
</template>
I'd like to run the initializer for the masonry library after all the templates and their subscriptions/helpers load within the main dashboard template.
Each card has code similar to this:
<template name="HighlightsCard">
{{#if highlightsExist}}
<div class="col-md-6 masonry-grid-item">
<div class="card highlights-card">
</div>
</div>
{{/if}}
</template>
Template.highlightsCard.onCreated(function() {
this.autorun(() => {
this.subscribe('userOwnClientHighlightsData');
});
});
Template.highlightsCard.helpers({
highlights() {
return Highlights.find({}, {
limit: 4,
sort: {createdAt: -1}
}).fetch();
},
highlightsExist() {
return (Highlights.find().count() > 0);
}
});
I currently am setting a session that increases when each onRendered is run within the card templates, but once they all render their contents have still not loaded. I need the class masonry-grid-item to be visible in order for me to initialize masonry.
What's the best way to get a similar result as jquery's $(document).ready() ?
Update: each individual card in the dashboard template has it's own subscription to a different dataset.