Accounts.emailTemplates customize with custom data from app

Hi guys.
In my app I let users create projects. They are able to invite more users to these projects. If the invited user is not already registered I use accounts sendEnrollmentEmail. I customize Accounts.emailTemplates.enrollAccount on meteor startup. However when sending this email I also need to put inside it the project name they are invited to. So should I customize and overwrite the the template each time it is being set, or is there some better way?

The template function takes a user object as its first argument. Therefore you can do something like:

Accounts.emailTemplates.enrollAccount.text = (user, url) => {
  // assuming that you are for example storing
  // an array of members' user id's in the projects collection
  const projectName = Projects.findOne({ members: user._id }).name;
  return `You are invited to join ${ projectName }, click ${ url } to set up your account and join the fun!`;