Tracker.autorun in Router action


I’m building a CMS which uses Iron Router . It’s at a very early stage but I want to be able to dynamically create a template based on a page source. If the page is changed I need the template to be destroyed, recreated with the new page source and then rendered.

Basically I think that I need an autorun inside an action as the psuedo code below outlines. It doesn’t of course work. :slight_smile: Does anyone one know if this is even possible? I have everything else working but I just cant figure out how to make it reactive on the page source :frowning:


Router.route('/:name', {
  waitOn: function() {
   return Meteor.subscribe('things');
  action: function() {
    var router = this;
    Tracker.autorun = function() {
      var thing = Things.find();
      if(thing) {
        Template['thing'] = buildANewTemplateUsing(thing);
  return whatShouldBeReturnedHere;

I did not played with it yet, but would experiment with data, not action.
Something like

I did consider that but I thought that the data was just passed to the template if you don’t specify an action. The docs show

Router.route('/post/:_id', function () {
  this.render('Post', {
    data: function () {
      return Posts.findOne({_id: this.params._id});

So if the data changes the template will be rerendered. However I need to destroy the template and create and render another on.

According this, there is onData hook which runs every time data changes ?

So in theory I would check if you can render new template from there ?
I dont use iron-router so :smiley:
just brainstorming, ignore if I am wasting your time

Thanks @shock I’d overlooked that…