Leveraging Smarty Statements for Dynamic Email Templates

LiveAgent's editor supports Smarty statements, a dynamic tool that can alter the content of your templates based on the profile details of your agents, customers, or ticket fields. This feature is especially handy if you want the content to change based on who's answering the ticket or who the customer is. Smarty statements in cooperation with template variables can check the profile details of agents, customers, or ticket fields, including custom fields, and depending on the selected field value change the content of the template dynamically.

To get started with Smarty language check out the official documentation here. For more detailed information about if/elseif/else conditions visit this page.

Using Smarty Statements within HTML Elements

As an example, let's say you want to add a formal salutation Mr. or Ms. to your email based on customer's profile gender field value. Or, if the gender is "other" or not specified, you want to state customer's full name. To achieve this, you can use the if/elseif/else conditions in Smarty to check the gender field and address the customer appropriately.

<p>
{if $firstRecipientGender eq 'M'}
Dear Mr. {$firstRecipientLastName},
{elseif $firstRecipientGender eq 'F'}
Dear Ms. {$firstRecipientLastName},
{else}
Dear {$firstRecipientName},
{/if}
</p>

The same approach can be applied to all variables available for the template you're working on, provided they're applicable. For instance, the above example works for Ticket Reply templates but not for New Ticket templates, as at the moment when the template is generated the system doesn't yet know the recipient's details when composing a new ticket.

Using Smarty Statements to Enclose HTML Code

If you want to use Smarty to dynamically alter the whole or a large portion of your email template, each if, elseif, and else condition must be enclosed in a separate paragraph with the inline CSS style display:none. This is required due to the functionality of the template editor.

For instance, if you have a common department in which agents are handling tickets in both Slovak and Czech languages, with e.g. two Slovak agents and four Czech agents, and you want to change half of the template based on the language the replying agent speaks, by using Smarty conditions, you can check the last name of the agent and generate the template in the respective language.

<p style="display:none;">
   {if $agentLastName eq 'Slovák' or $agentLastName eq 'Podhorský'}
</p>
<p>
   Dobrý deň {$firstRecipientFirstName},
</p>
<p>
   {$message}
</p>
<p>
   S pozdravom a prianím príjemneho dňa
</p>
<p style="display:none;">
   {else}
</p>
<p>
   Dobrý den {$firstRecipientFirstName},
</p>
<p>
   {$message}
</p>
<p>
   S pozdravem a přáním příjemného dne
</p>
<p style="display:none;">
   {/if}
</p>
<p>
   {$agentName}<br>
   {$agentSignature}<br>
   My Company Co.
</p>
×