0

I'm working on a shared calendar app. I have the following (simplified) template structure:

<template name="meeting">
    {{> calendar}}
</template>

<template name="calendar">
    {{#each days}}
        {{> day}}
    {{/each}}
</template>

<template name="day">
    etc etc
</template>

I have a ReactiveVar for the state of each day that's setup like so:

Template.day.created = function(){
  this.state = new ReactiveVar();

  this.autorun(_.bind(function() {
    var thisDate = Meetings.findOne(this.data._id).dates[this.data.dateString];
    s = ...various stuff...
    this.state.set(s);
  }, this));
}

And routes set up like so (I'm using my own uuids instead of Mongo ids for public urls):

Router.map(function () {
  this.route('home', {path: '/'});
  this.route('meeting', { 
    path: '/meeting/:uuid',
    template: 'meeting',
    data: function() {
      return Meetings.findOne({"uuid":this.params.uuid});
    }
  });
});

The core problem as I understand it is that Template.day.created does not have a data context (yet), so I need a way to pass in the _id (or uuid) of the meeting. What is the right approach for providing this context?

Stennie
  • 63,885
  • 14
  • 149
  • 175
T3db0t
  • 3,491
  • 4
  • 28
  • 45
  • The data context should be available inside your created callback as `this.data`, so you should be able to use `this.data._id` . This is just a non-reactive, read-only value however. – sbking Dec 23 '14 at 01:14
  • Right; but for some reason at the time the callback is called, data is `null`, so I think this might be going on: http://stackoverflow.com/questions/25803169/meteor-template-data-context-not-available-in-template-created-upon-refresh – T3db0t Dec 23 '14 at 02:20
  • @VirgilDisgr4ce, yea, you need to have the data (the subscription containing the data must be ready) before you can use it in your template. – Peppe L-G Dec 23 '14 at 14:24

1 Answers1

1

You could try doing this:

Router.map(function () {
  this.route('home', {path: '/'});
  this.route('meeting', { 
    path: '/meeting/:uuid',
    template: 'meeting',
    waitOn: function() {
      return Meteor.subscribe('Meetings');
    },
    data: function() {
      return Meetings.findOne({"uuid":this.params.uuid});
    }
  });
});
jusynth
  • 183
  • 7