MailScript to insert HTML

Jamsta1912
Tera Guru

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:

message_html.PNG

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

1 ACCEPTED SOLUTION

I would recommend doing all of the html in the mail scripts, so something like:



  1. 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>');
  2. if(something){  
  3. var str = '<tr><td>A</td><td>B</td><td>C</td></tr>';  
  4. template.print(str);  
  5. }  
  6. template.print('<tr><td>7</td><td>8</td><td>9</td></tr></tbody></table><p></p><p> </p>')

View solution in original post

3 REPLIES 3

Jamsta1912
Tera Guru

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>


I would recommend doing all of the html in the mail scripts, so something like:



  1. 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>');
  2. if(something){  
  3. var str = '<tr><td>A</td><td>B</td><td>C</td></tr>';  
  4. template.print(str);  
  5. }  
  6. template.print('<tr><td>7</td><td>8</td><td>9</td></tr></tbody></table><p></p><p> </p>')

Thank you Andrew. A much cleaner solution and I have it working fine!