Reputation: 3772
In the iron-router path definition you can use variables, like in this example in the docs: https://github.com/EventedMind/iron-router#controlling-subscriptions
This is all fine and it does exactly what I want except I son't want to do this in the waitOn clause but in the rendered callback for a specific sub template. I have several of these and I would like them to render independently and not on load as waitOn suggests.
My router looks like this:
Router.map( function () {
this.route('de', {
path: '/monitor/DE/:period',
data: function () {
return {subtitle: "Germany - " + this.params.period + " data"};
}
});
});
I also have some template code that run on rendered to draw a d3 graph. In this function I define a Deps.autorun containing a subscription.
Template.de.rendered(function (){
// lots of d3 stuff...
// Automatically redraw on change
Deps.autorun(function () {
Meteor.subscribe("count", "hourly");
});
});
I publish the collection with _id as timestamps using a parameter like this:
Meteor.publish("count", function(period) {
if(period == "hourly") {
return Count.find({_id: {$gt: new Date().getTime() - 3.6e6*24}},
{sort: {_id: -1}});
} else {
return Count.find({_id: {$gt: new Date().getTime() - 3.6e6*24*30}},
{sort: {_id: -1}});
}
});
This code works fine, but I have hard coded the parameter in the subscription. I would like to use the path variable to change the subscription scope.
How can i use an iron-router path variable to change a subscription in the Template.x.rendered callback?
Upvotes: 1
Views: 233