Passing data from one template to another


#1

Let’s say I have two templates included on a page:

{{> dataEntry }}
{{> calculations }}

And I want to take variables from dataEntry and send them over to calculations. Not stuff in MongoDB either, just variables. I know session variables are one way, but I’d rather avoid using them.


#3

Or you can use a Local (unmanaged) Collection and use my package https://atmospherejs.com/vjau/localcollections-persister that allow them to persist between hot codes pushes.
Once the session has ended, all data is gone.


#4

that’s a great idea –


#5

I’d rather not have to use a package to do this.

So let’s say I have a ReactiveVar within a template:

Template.templateOne.onCreated(function() {
  this.myVar = new ReactiveVar(0);
});

And I’m using myVar within templateOne, but then I want to share this value with templateTwo. I just tried this and it seems to work, actually:

Template.templateTwo.someOtherVar = Template.instance().myVar.get();