mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
add support for passing arbitrary non-GraphQL data to email template
This commit is contained in:
parent
0a6034aed1
commit
8d6855d09c
4 changed files with 12 additions and 13 deletions
|
@ -10,11 +10,9 @@ VulcanEmail.addEmails({
|
|||
customEmail: {
|
||||
template: "customEmail",
|
||||
path: "/email/custom-email",
|
||||
getProperties() {return {};},
|
||||
subject() {
|
||||
return "My awesome new email";
|
||||
},
|
||||
getTestObject() {return {};}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
|
@ -5,15 +5,12 @@ VulcanEmail.addEmails({
|
|||
test: {
|
||||
template: "test",
|
||||
path: "/email/test",
|
||||
getProperties() {
|
||||
data() {
|
||||
return {date: new Date()};
|
||||
},
|
||||
subject() {
|
||||
return "This is a test";
|
||||
},
|
||||
getTestObject() {
|
||||
return {date: new Date()};
|
||||
}
|
||||
}
|
||||
|
||||
});
|
|
@ -96,11 +96,13 @@ VulcanEmail.send = (to, subject, html, text) => {
|
|||
|
||||
};
|
||||
|
||||
VulcanEmail.buildAndSend = async ({ to, email, variables, data }) => {
|
||||
VulcanEmail.buildAndSend = async ({ to, email, variables }) => {
|
||||
|
||||
// either use data passed as argument, or execute email's GraphQL query
|
||||
const result = await runQuery(email.query, variables);
|
||||
const emailData = data || result.data;
|
||||
// execute email's GraphQL query
|
||||
const result = email.query ? await runQuery(email.query, variables) : {data: {}};
|
||||
|
||||
// if email has a data() function, merge its return value with results from the query
|
||||
const emailData = email.data ? {...result.data, ...email.data()} : result.data;
|
||||
|
||||
const subject = typeof email.subject === 'function' ? email.subject(emailData) : email.subject;
|
||||
const html = VulcanEmail.buildTemplate(VulcanEmail.getTemplate(email.template)(emailData));
|
||||
|
|
|
@ -19,8 +19,10 @@ Meteor.startup(function () {
|
|||
} else {
|
||||
|
||||
// else get test object (sample post, comment, user, etc.)
|
||||
const result = await runQuery(email.query, email.testVariables || {})
|
||||
const emailTestData = result.data;
|
||||
const result = email.query ? await runQuery(email.query, email.testVariables || {}) : {data: {}};
|
||||
|
||||
// if email has a data() function, merge it with results of query
|
||||
const emailTestData = email.data ? {...result.data, ...email.data()} : result.data;
|
||||
const subject = typeof email.subject === 'function' ? email.subject(emailTestData) : email.subject;
|
||||
|
||||
// then apply email template to properties, and wrap it with buildTemplate
|
||||
|
|
Loading…
Add table
Reference in a new issue