- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2017 08:13 AM
Hello all,
I have an email notification set up with some message HTML that contains a table.
For most of the emails generated by this notification, the table needs to contain a set number of rows, but in certain circumstances the table needs to contain an extra row with additional info for the end user.
I am trying to use a mail script called 'html_test' to insert the additional row in the table when the conditions are met, but I'm struggling with how to add the ${mail_script:html_test} line to the message html field. My simplified Message HTML looks like this:
for which the raw HTML is:
<p></p>
<table border="1" width="200">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
<p> </p>
My simplified mailscript, html_test, looks like this:
//Insert a row into the table
if(something){
var str = '<tr><td>A</td><td>B</td><td>C</td></tr>';
template.print(str);
}
The idea is to use this to insert a row containing 'A', 'B', 'C' above the row in the table containing '7', '8', '9'.
So I want to do something like this below:
<p></p>
<table border="1" width="200">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
${mail_script:html_test}
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
<p> </p>
but this doesn't give me the result I'm after.
Can anyone advise how I use a mailscript to insert additional HTML into the message HTML to achieve this?
Thanks
Jamie
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2017 08:48 AM
I would recommend doing all of the html in the mail scripts, so something like:
- template.print('<table border="1" width="200"><tbody><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>');
- if(something){
- var str = '<tr><td>A</td><td>B</td><td>C</td></tr>';
- template.print(str);
- }
- template.print('<tr><td>7</td><td>8</td><td>9</td></tr></tbody></table><p></p><p> </p>')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2017 08:19 AM
Oh, that post didn't look quite how I'd intended. I was expecting the inserted raw HTML to stay as HTML.
The raw code at the end, where I've inserted the reference to the mailscript within the message HTML, looks like this:
<table border="1" width="200">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td>5</td>
<td>6</td>
</tr>
${mail_script:html_test}
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</tbody>
</table>
<p></p>
<p> </p>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2017 08:48 AM
I would recommend doing all of the html in the mail scripts, so something like:
- template.print('<table border="1" width="200"><tbody><tr><td>1</td><td>2</td><td>3</td></tr><tr><td>4</td><td>5</td><td>6</td></tr>');
- if(something){
- var str = '<tr><td>A</td><td>B</td><td>C</td></tr>';
- template.print(str);
- }
- template.print('<tr><td>7</td><td>8</td><td>9</td></tr></tbody></table><p></p><p> </p>')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-04-2017 09:53 AM
Thank you Andrew. A much cleaner solution and I have it working fine!