Skip to content

Instantly share code, notes, and snippets.

@beanmoss
Created June 1, 2016 10:14
Show Gist options
  • Save beanmoss/27041eabd29f8e29f8334e033deee1f5 to your computer and use it in GitHub Desktop.
Save beanmoss/27041eabd29f8e29f8334e033deee1f5 to your computer and use it in GitHub Desktop.
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