Created
June 1, 2016 10:14
-
-
Save beanmoss/27041eabd29f8e29f8334e033deee1f5 to your computer and use it in GitHub Desktop.
email template replace vars meteor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
%val1% %val2% | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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