Dynamic coding for smarter and more efficient templates

Dynamic code in templates can save a lot of time for a lot of different scenarios. Not only will you not have to go through your data with a fine toothcomb to fix things to fit your template requirements, you may also only have to make one template rather than multiple ones, saving significantly on development time and resources. Here are just some of the solutions our platform can offer to really help save time and effort when it comes to perfecting your templates:

Personalisation using titles, first names and last names

One very common issue you may find, is you want to use personalisation in your email, be it a salutation or in the subject line, but you have the problem where not all your data is fully populated, for example:

Salutation: Dear First Name,


Subject line: Hello First Name, we have something special for you…

If First Name is missing you’re going to look a little silly. Now, you could update this record with a generic salutation e.g. “customer” but then you’re running the risk of corrupting your data and misusing the replacement name for a future, different scenario. You might also have a title and last name at your disposal which could be a decent replacement, but you don’t want to have to generate a whole new field just to hold the various combinations. What could be preferable is to leave your original record as it was and instead use dynamic code to fix the problem.

Dear {?$contacts_first_name|default:'customer'?},

The default modifier acts as a fall back, so if first name is empty, it replaces the contents of your template only with your chosen text, in this case, customer. If you’d rather not replace the name with something generic and just say “Hi,” rather than “Dear First name,” then you may end up with an unwanted space. This leads us on to…

Conditional content

With simple if…else statements you can make your template display whatever you want. As in the above example we can now do away with our generic name replacement in the subject line with:

Subjectline: Hello{?if $contacts_first_name!=”?} {?$contacts_first_name?},{?else?},{?/if?} we have something special for you…

So, if the first name is not blank we will add a space followed by a comma, otherwise just a comma. Or we can try replacing it with title and last name first before making it blank:

Subjectline: Hello{?if $contacts_first_name!=”?} {?$contacts_first_name?},{?elseif $contacts_title!=” && $contacts_last_name!=”?}{?$contacts_title?} {$contacts_last_name?},{?else?},{?/if?} we have something special for you…

Our Dynamic Test:

  1. Dear {?$contacts_first_name?},
  2. {?if trim($contacts_first_name) != ”?}Dear {?$contacts_first_name?}{?else?}Hi{?/if?},
  3. {?if trim($contacts_first_name) != ”?}Dear {?$contacts_first_name?}{?elseif trim($contacts_title) !=” && trim($contacts_last_name)!=” ?}Dear {?$contacts_title?} {?$contacts_last_name?}{?else?}Hi{?/if?},

Dynamic Salutation Modification

Here we have a non-populated email followed by two emails with different conditions, the first having First Name, the second only Title and Last Name available. You can see that for test 1, without the first name it doesn’t work. For test 2, the dynamic content has worked and we either get Dear First Name or a simple Hi. Then for test 3 we either get Dear First name or Dear Title + Last Name leaving the data unaffected.

Another scenario could be your company has multiple branches, each with different information, but you want to send roughly the same information to them all, but just change things like their contact details and location. You naturally will have no desire to make 20 different templates just to accommodate little changes, so having the ability to simply drop in these details based upon something like a store ID will save an inordinate amount of time and resources.

To show this feature off, I have used favourite dinosaurs as an example:

Dynamic Content Example


There is a whole assortment of other things you can do to tweak your data within a template – here are some examples:

Using the current date:
Today’s Opening Times ({?$date|date_format:”%A”?}) are:

{?if $date|date_format:”%A”== “Wednesday”?}CLOSED{?elseif $date|date_format:”%A”== “Monday” || $date|date_format:”%A”== “Tuesday” || $date|date_format:”%A”== “Thursday” || $date|date_format:”%A”== “Friday”?}9am-5pm{?else?}11am-4pm{?/if?}

Making your text upper or lower:
{?$contacts_data_7?} when capitalised becomes {?$contacts_data_7|upper?}

Extending your text:
You can add your own text so {?$contacts_data_7?} becomes {?$contacts_data_7|cat:’ is my favourite dinosaur.’?}

Escaping your text:
You can escape your tag to make it html and url friendly: {?$contacts_data_8|escape:’url’?}

Other Dynamic Modification Examples

We feel we have a fantastic array of dynamic elements to transform your template into a practical living entity, the examples shown are just a taster of what we can offer, so if you’re looking for a solution to save you on time and resource when it comes to developing highly functional templates then our solution should give you everything you need.