Skip to content

Instantly share code, notes, and snippets.

@beanmoss
Created June 1, 2016 10:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
email template replace vars meteor
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
%val1% %val2%
</body>
</html>
Meteor.method({
'email.send': function(filter){
//Do some collection action here to get data based on filter
var data = {
val1: 'Hello',
val2: 'World'
};
// get content of this file located under /private
var template = Assets.getText('email.template.html');
// search and replace
var result = template.replace(/%(\w*)%/g, function (m, key) {
return data.hasOwnProperty(key) ? data[key] : "";
})
//email the result.
console.log(result);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment