News! SmartSender.io becomes Wooxy. Read a post from the CEO Arrow
October 12, 2018

Dynamic Email Template

Wooxy supports a large subset of the Twig templating language. Below are examples for some common templating use-cases.

Variable Replacement

Simple variable replacement can be achieved using the following syntax.

API Call

JSON
                {
  "variables": [{
    "name": "firstName",
    "value": "John"
   }, {
   "name": "image",
   "value": "http://domain.com/image.gif"
  }, {
  "name": "link",
  "value": "https://app.wooxy.com"
 }]
}
            

Template HTML

HTML
                <p><b>Hello, {{ firstName }}</b></p>

<img src="{{ image }}">

<a href="{{ link }}">Go to Wooxy</a>
            

Rendered HTML

Hello,  John

Conditional Content

Conditional syntax can be used to include/exclude email content based on data passed into API calls or stored in contact list.

API Call

JSON
                {"variables": [ {
   "name":   "paidCustomer",
   "value":  false
  }, {
  "name":   "signupType",
  "value":  "referral"
 }],
            

Template HTML

HTML
                {% if paidCustomer %}
  Thanks for being a customer!
{% else %}
  Sign up today and get 30% off!
{% endif %}

{% if signupType == 'referral' %}
  <a href="https://app.wooxy.com">Refer your friends!</a>
{% endif %}
            

Rendered HTML

Sign up today and get 30% off!

Refer your friends!

HTML in Variables

Most of your HTML needs can be met in our template editor. If you are using user-generated HTML and you need to pass raw HTML as a variable, you’ll need to escape it with Twig raw filters or autoescape tags.

API Call

JSON
                {"variables": [ {
   "name":   "message",
   "value":  "<h4><b>Hello</b></h4><p><b>World</b></p>"
  }],
            

Template HTML

HTML
                {{ message|raw }}
   <a href="https://app.wooxy.com">
  </a>
            

Rendered HTML

Hello World

Go to Wooxy

Formatting Numbers

Most of your HTML needs can be met in our template editor. If you are using user-generated HTML and you need to pass raw HTML as a variable, you’ll need to escape it with Twig raw filters or autoescape tags.

API Call

JSON
                {"variables": [ {
   "name":   "price",
   "value":  9800.333
  }]
            

Template HTML

HTML
                <p><b>Numbers:</b><p>
    <ul>
      <li>{{ price|round }}</li>
      <li>{{ price|round(1, 'floor') }}</li>
      <li>{{ price|number_format(2, '.', ',') }}</li>
      <li>{{ price|number_format(0, '.') }}</li> 
      <li>{{ "$%.2f"|format(price) }}</li> 
    </ul>
            

Rendered HTML

Numbers:

9800

9800.3

9,800.33

9 800

$9800.33

Formatting Dates

The following example illustrates how to use Twig filters to achieve date formatting of both timestamps and ISO 8601 date strings.

API Call

JSON
                {"variables": [ {
   "name":   "timestamp",
   "value":  "1539377301"
  },{
  "name":   "isoDate",
  "value":  "2016-04-29T15:47:28+02:00"
 },]
            

Template HTML

HTML
                <p><b>Flexible date formating</b></p>
<p>Current date: {{ "now"|date("m/d/Y") }}</p>
<p>isoDate: {{ isoDate|date("D, F y") }}</p>
<p>timeStamp to custom: {{ timestamp|date('g:ia \o\n l jS F Y')}}</p>
            

Rendered HTML

Flexible date formating

Current date: 10/12/2018

isoDate: Fri, April 16

timeStamp to custom: 8:48pm 2018 Friday 12th October 2018