Saving Objects in a session


#1

I want to provide a session variable to provide data to 3 different templates. So I can’t use ‘ReactiveDict’ or ‘ReactiveVar’ Packages.

In one of the templates I have this in the onCreated Hook:

Session.set('previewField', {title: '', terms: '', expiry: '' });

In another template I set the specific fields, based on user action

Template.couponInsert.events({
  'keyup #title'(event) {
    const value = event.target.value;
    // go for my object now
    const sessionObj = Session.get('previewField');
   // update the title field
    sessionObj.title = value;
  // Save the new sessionObj
    Session.set('previewField',sessionObj);
  }
});

Is there a better way sharing data across several templates. Maybe with a local collection. Any advise on this subject. Thank you very much community!


#2

I think using session is fine.