Adding condition in Email template

We have met a scenario where we need to take the difference between two field and convert that answer in to 2 decimal points

<tr>
<td style="font-family: sans-serif; padding: 8px; height: 4px; width: 65px;">&nbsp;</td>
	<td style="font-family: sans-serif; padding: 8px; height: 4px; width: 65px;">&nbsp;</td>
<td style="font-family: sans-serif; padding: 8px; width: 231px;"><span style="display: block;margin-top: 2px;font-family: sans-serif;text-align: right;">Shipping Fee</span>
</td>
	<#assign shippingcostvalue=(transaction.shippingcost)-(transaction.custbody_srtipesubtotal)>
        <#if (shippingcostvalue)?has_content>
	<td shippingcostvalue="${shippingcostvalue}" style="font-family: sans-serif; padding: 8px; text-align: right; width: 285px;display: block;"><span>$</span>${shippingcostvalue?string[&quot;#,##0.00&quot;]}</td>
	<#else>
	<td shippingcostvalue="${shippingcostvalue}" style="font-family: sans-serif; padding: 8px; text-align: right; width: 285px;display: block;">$0.00</td>
	</#if>
</tr>

Here the two field are ‘transaction.shippingcost’ and ‘transaction.custbody_srtipesubtotal’. So taking the difference between these fields and assigning that two a variable ‘shippingcostvalue’ .Then checking whether the variable ‘shippingcostvalue’ has content. If there is content then adding a $ sign and converting the value to two decimal point. If there is no value then showing $0.00 as static value.

Leave a comment

Your email address will not be published. Required fields are marked *