HomeArctic Reservations v2EmailsAdvanced Logic (Smarty)

17.9. Advanced Logic (Smarty)

The format used in email templates (and other places in Arctic) is known as Smarty, a special language for building flexible templates. The "Placeholders & Logic" chapter covers some of the basics, showing how information can be filled into templates. But beyond simply filling in information, Smarty offers nuanced control over email content. Below are some additional Smarty expressions that you might find useful for the more complex scenarios when creating email templates.

These tend to be more advanced, and require a basic knowledge of some coding principles, although examples that can be used verbatim are included below.

Conditional statements

It is common to run into a scenario in your email templates where you want to have Arctic include certain text and/or information but only if a certain condition is met. For instance, you might want to only include information regarding the "Group Booking Link" and the link itself if the reservation is a group mode reservation. To accomplish this you will use an "if" statement. The Smarty code for an "if" statement looks like this:

{if $reservation->bookurl}
We have set your reservation up a group-reservation, meaning your fellow guests can each register separately. We have created a special page where those joining your group can reserve their spot(s), fill out their registration forms and pay for themselves. Please give this link to other members of your party:
{$reservation->bookurl}{/if}

The Smarty for the "if" statement is highlighted in yellow. Essentially this Smarty code is telling Arctic that, if there is a group booking link for the reservation, include the text and any normal placeholders found between the opening "if" tag {if condition} and the closing "if" tag {/if}.

You can also test for other details, like specific trips or specific pickup locations (for example, if you use a custom field to store pickup information). Below is code to test the trip name and only show certain information for guests on a specific trip:

{if trip->name == "Upper River"}The upper river includes some intense rapids. Be sure to come prepared to get wet.{/if}

Note the two equal signs used to see if the trip name is exactly equal to "Upper River."

You can use "if" statements for many scenarios in email templates and they will all be formatted pretty much as shown above. 

Modifiers

Modifiers allow you to customize a placeholder before it is inserted. Most commonly, this is used for formatting currency values, dates and times. A modifier is added using a vertical pipe |, followed by the modifier name. Modifiers can then have arguments or settings after colons :.

The most commonly used modifier in Arctic is a custom one, called "format" that does all the formatting heavy work and it always takes one argument that tells it what format to use.

For example:

{$invoice->balancedue|format:'Currency'} prints $1,234.50

{$invoice->nextpaymentdueon|format:'Date'} prints 3/31/15

The format modifier handles the following arguments:

  • Number - adds correct commas between sets of three digits
  • Currency - adds the dollar sign, commas between sets of three digits and two decimal points
  • Date - a date in the format mm/dd/yy
  • DateLong - a long version of the date (e.g., "Monday, March 3, 2015")
  • Time - a time
  • DateTime - a date and time combination
  • DateOrDateTime - some trips have no start time, so "DateTime" would just print midnight for the time; this modifier will only print the time if it is NOT midnight
  • Duration - the number of days, minutes and seconds in the duration
  • AddOrdinalSuffix - takes a number (like 1) and adds the right ordinal suffix ("st") so it prints 1st
  • FileSize - converts a number of bytes into the best file size (e.g., 1.2 MB)

Note: The modifier arguments listed above should be enclosed in single quotes ' ' to ensure they work properly. 

There are other built in modifiers that are included with Smarty, that can be helpful for capitalization or other minor adjustments. For example, "capitalize" will capitalize the first letters of words.

{$trip->name|capitalize} prints Trip Name (ensuring that each word in the name is capitalized)

Dates & times

Certain placeholders store date/time information, which has a lot of special formatting options. A good example is {$trip->start} which contains the date and, optionally, the time that a trip starts.

You can print the full date and time information using a format modifier:

{$trip->start|format:'DateTime'} prints 5/1/2014 3:00pm

Or just one part (either the date or time) can be printed, again using the appropriate format modifier:

{$trip->start|format:'Date'} prints 5/1/2014

{$trip->start|format:'Time'} prints 3:00pm

Date & time math

Dates and times can be manually modified, which is helpful for printing "check-in" times or other details that are not covered by the standard placeholders.

For exmaple, a check-in time 30 minutes before a trip starts could be printed as follows in Smarty:

{$trip->start->subtractMinutes(30)|format:'DateTime'} prints 5/1/2015 2:30pm

The function subtractMinutes in the previous example creates a new date time object representing the adjusted time, and it can be printed using the standard modifiers.

There are several functions that can be used on date and/or time objects:

  • addSeconds
  • subtractSeconds
  • addMinutes
  • subtractMinutes
  • addHours
  • subtractHours
  • addDays
  • subtractDays

The above codes cover some of the more common scenarios that require some more advanced Smarty code, but if you have any trouble with the above or have questions about how to achieve specific content in your emails, feel free to contact support and we will be happy to help. 

Related Pages
This page was: Helpful | Not Helpful