Using Smarty, you can randomize blocks of content in a message. The content will be randomized at send time or during message preview. This is useful if you need to display advertising content randomly in a message.
In this example we will assign a variable with a random value between 1 and 4. Then in the content we can use an {if}{else} statement to print the random result.
{$data.min = 1}
{$data.max = 4}
{$data.random = "{math equation='rand(min, max)' min=$data.min max=$data.max}"} {if $data.random == 1} Ad 1 {elseif $data.random == 2} Ad 2 {elseif $data.random == 3} Ad 3 {else} Ad 4 {/if}
<h1>Debug Data</h1> {$utils->jsonPrettyPrint($data)}
<br><hr><br>
Every time the message is sent or previewed, the content will change according to the number that was selected at random by Smarty.
In the next article learn about calculating distance between postal codes.
Comments
0 comments
Please sign in to leave a comment.