eladnava/mailgen

Add two buttons instead of just one

gemueselasagne opened this issue ยท 8 comments

Hi!
I am using mailgen for sending out transactional mails. For a new feature I need two different buttons in one mail. Just tried it out to simply use two action-objects but mailgen seems to just take the second one and ignore the first. Does someone know how to do it?
Cheers

Hi @gemueselasagne,

Great suggestion! Displaying more than one action button in generated e-mails is currently not possible out of the box, but that could definitely be changed!

A PR could be submitted to make it possible to pass in body.action as an array (and support an object as well) to mailGenerator.generate, as well as modifying each built-in theme to render all passed in action buttons in the respective templates' HTML and TXT files.

Let me know if anyone would like to work on this. ๐Ÿ˜„

@eladnava i'd like to give it a shot!

@collnwalkr Awesome! Would you like some tips on how to implement this? ๐Ÿ˜„

@eladnava sure! But first this is what I've done so far.
First, I edited welcome.js's email.action to be an array:

var email = {
    body: {
        // removed for brevity
         action: [
             {
                 instructions: 'instruction',
                 button: {
                     color: '#22BC66',
                     text: 'button',
                     link: 'https://www.google.com/'
                 }
             },
             {
                 instructions: 'instruction 2',
                 button: {
                     color: '#33BC66',
                     text: 'button2',
                     link: 'http://www.bing.com/'
                 }
             }
         ],
        // removed for brevity
    }
};

Then that led me to ejs.render on index.js line 71. It looks like the fix might have to be applied to every theme. Do you think that would be an acceptable solution? I could also edit THEME.md to reflect the upgrade.

@collnwalkr Absolutely! You are on the right path. You will indeed need to modify each theme separately, adding support for more than one action button (and also supporting just one action if passed in).

Specifically, in the default theme for example, this would be the section to modify:

<% if (locals.action) { %>
<p><%- action.instructions %></p>
<table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<div>
<a href="<%- action.button.link %>" class="button" style="background-color: <%- action.button.color %>" target="_blank"><%- action.button.text %></a>
</div>
</td>
</tr>
</table>
<% } %>

You could employ an ejs forEach loop like so:

<% outro.forEach(function (outroItem) { -%>
<p><%- outroItem %></p>
<% }) -%>

@eladnava thanks. I've already made good progress. I'm wondering what Gmail Go-To Actions are? Will these be impacted?

alright here's my solution: #18

@collnwalkr Great!

No need to worry about the Gmail Go-To Actions. There seems to be no way to provide more than one according to the docs.