leemunroe / grunt-email-workflow

A Grunt workflow for designing and testing responsive HTML email templates with SCSS.
MIT License
3.05k stars 339 forks source link

How to edit content on templete #97

Closed chayakornwc closed 6 years ago

leemunroe commented 6 years ago

@chayakornwc The content of the emails are in /src/emails/*.hbs

Have you tried changing the content here?

chayakornwc commented 6 years ago

sorry, i mean changing content at variable, my data is callback from database query.

taeo commented 6 years ago

@chayakornwc - Can you please post some sample code to help us help you? Explain the problem in as much detail as possible with the sample code.

chayakornwc commented 6 years ago
 connection.query("SELECT p.*, c.course_name, concat(r.prefix,' ',r.first_name,' ',r.last_name) as fullname, r.email FROM period p LEFT OUTER JOIN course c ON p.course_id = c.course_id LEFT OUTER JOIN course_order co ON co.per_id = p.per_id  LEFT OUTER JOIN  registration r  ON r.id  = co.registration_id WHERE p.per_start = CURDATE()  +INTERVAL 1 DAY", function(err,results){
            if(err) throw err;
            var data = {
                from: 'Computer Center <notification@computercentre.lpru.ac.th>',
                to: '',
                subject: '',
                };
           results.forEach(e =>{
              data.to = e.email
              data.subject = ` ${e.course_name}  ${moment(e.per_end).add(543, 'years').format('ll')}`
              data.html = `<!doctype html>.........</html>`

look at ${e.course_name} ${moment(e.per_end).add(543, 'years').format('ll')} i need insert these data to email content

taeo commented 6 years ago

@chayakornwc - Looks like you are just trying to change the to and subject fields. These would be things you'd do with your ESP / Mail Service. Grunt email workflow just compiles templates to send.

If you needed variable replacement w/in the actual HTML template being sent to each person, you can use custom variables / syntax and replace that when processing the template for each send.

Template Example:

<!-- other code -->
Hello and thank you for choosing %%course_name%%!
<!-- other code -->

☝️ %%course_name%% would need to be replaced by your value e.course_name in your loop when sending/queuing emails i.e data.html = templateReplaceStrings(your_args)

chayakornwc commented 6 years ago

Thanks for help. 👍