How to reference a Template ReactiveVar from Tracker.autorun callback?

I want to use my ReactiveVar bar declared in as a reactive data source in a Tracker that’s called even after bar assigned a value. In the context of the Tracker’s callback Template.instance().bar is null and thus I cannot get/set/track its value. I don’t want to use a Session variable for this purpose so how can I reference my Template instance variable from the Tracker? Also bonus: I have this same issue within Meteor.subscribe onReady callback. Will the solution for the first problem apply to this as well? = function() { = new ReactiveVar([]);
} = function() {
  Tracker.autorun(function() { 
    console.log(Template.instance().bar.get()); // Template.instance().bar is null
} () {
  this.autorun(() => { 
    console.log(; // Template.instance().bar is null
1 Like

Or create a constant for the template. Granted this approach is more verbose, but increases readability, IMHO.

Also, I think you should use Template.onRendered( callback ) rather than Template.rendered = callback function() {
  const template = this; = new ReactiveVar([]);
}); function() {
  const template = this;
  template.autorun(function() { 

Also note how I tied the autorun to the template. This way the autorun is destroyed when the template is destroyed.