Tracker.autorun in Router action

Hi,

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:

Thanks
Rob

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);
        router.render(Template['thing']);
     }
   }
  return whatShouldBeReturnedHere;
}

I did not played with it yet, but would experiment with data, not action.
Something like http://stackoverflow.com/questions/27910775/meteor-change-the-iron-router-data-reactive-variable-without-page-reload

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 ?
https://gentlenode.com/journal/meteor-11-iron-router-cheatsheet/18

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…