TracCloud: Twig: Difference between revisions

From Redrock Wiki

No edit summary
No edit summary
 
(115 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{TracCloudGuideTabs}}
{{TracCloudGuideTabs}}
{| style="width:100%; vertical-align:top; "
<div class="tcWidgetPage">
| style="width:250px; vertical-align:top; padding:2px 15px 2px 2px;" | {{TracCloudGuideProfileTOC}}
<div class="categoryDynamic">
| style="vertical-align:top; padding:20px 20px 20px 2px;" |
{{TracCloudGuideProfileTOC}}
{| style="width:100%; vertical-align:top; "
</div>
<big><b>Formatting Text in TracCloud with Twig and HTML</b></big><br><br>
<div class="pageTitle">TracCloud Twig Guide</div>
Many text boxes throughout TracCloud support Twig, this allows greater control in determining how emails are formatted and what data is included. HTML is also supported, allowing to you adjust the formatting of text. From font sizes, colors, and types, to embedding images and video.
 
<br><br>
Many text fields throughout TracCloud support Twig and HTML, giving you greater control in determining what data is displayed to your students, staff, and faculty based on the context of appointments, visits, and more, as well as formatting that data to be as clear as possible.
Twig allows you to pull data from various TracCloud fields to be included in emails and texts via our tag system. We can also use Twig to apply logic to our text. Maybe we only want to include a block of text if the student selected a specific reason, or if a certain Recommendation was selected in a SAGE referral.
 
<br><br>
<b>Twig</b> will be the primary focus of this article. Twig is a template engine that serves two primary purposes in TracCloud:
This chapter will be going over several Twig options available, however, this is not an in-depth guide. Twig isn’t exclusive to TracCloud, and there are many resources available online for more complex configurations if you’d like to go a step further. The point of this chapter is to give some brief examples and possible configuration ideas that you can build off of.
 
<br><br>
* <b>1. Print variables in text</b>
Most of the examples here will be formatted for an appointment confirmation email, but Twig can also be utilized in SAGE referral emails and in the upcoming appointments screen for students and consultants. The same concepts apply across the board.
::Personalize your emails and messages. Greet the student by name, let them know what subject they selected in their appointment, what time their appointment takes place, the location, and more. These same variables are also used for purpose #2.<br>
 
* <b>2. Add logic to your text</b>
::Modify the email or message based on why it was sent. Add an extra paragraph if Reason X was selected, send a follow-up email after a visit if the student chose Y, prevent an email from being sent on a SAGE referral if Z recommendation was checked, and much more. Rather than creating a generic email for any context, create a dynamic email that changes to match your needs.<br><br>
 
Twig (and HTML) are supported in [[TracCloudGuideProfilePrefsEmails|profile emails]], [[TracCloud:_Welcome_Messages|welcome messages]], [[TracCloud:_Email_Templates|email templates]], [[TracCloudGuideProfilePrefsScheduleDisplay|appointment display]], and more. Most of the examples listed in this article are for appointment emails or SAGE referrals, but the same concepts apply in all other supported fields. It's also worth keeping in mind that Twig exists outside of TracCloud, and there are many resources online for how you can utilize it that will also work here (such as [https://twig.symfony.com/doc/3.x/ Symfony]). This guide likely covers everything you will need, but it doesn't cover everything that Twig is capable of.<br><br>
 
<b>HTML</b> will also be used sparingly throughout this article, but without much explanation as it's more ubiquitous than Twig. There are many excellent resources online explaining how to use this markup language, such as [https://www.w3schools.com/html/html_styles.asp W3Schools]. HTML is used to adjust font sizes and colors, embed images and videos, and more.
 
==Part 1. Syntax, Terminology, and Essential Knowledge==
When reading the wiki or talking to support, you will often see fields like <i>Student.First_Name</i> or <i>Courses.Subject</i> referred to as "Twig tags." To use another term, these are <b>variables</b>. They contain data, it's up to you what you do with that data through Twig. If you're at all familiar with any programming languages, then you likely already know the concepts. This article will provide you with the necessary knowledge to use Twig in TracCloud, regardless of your current knowledge level.
 
<span style="color:red; font-weight: bold;">Important:</span> [[TracCloud:_Rosetta|A complete list of Twig tags can be found here.]] Not all tags can be used in all places, but you can almost always predict what will and won't work in a given location. For example, in the [[TracCloud:_Emails|Appointment Confirmation Email]], you can expect to use Student, Reason, Subject, Staff tags, etc. Whereas in the [[TracCloud:_Log_Listing_Message,_KIOSK_Notices,_and_Custom_KIOSKs|Notices on KIOSK]], you can only use Center tags. This is because when that message is displayed at the top of an idle kiosk, nothing ties that message to any one Student or Staff record, let alone Registrations, Reasons, etc.
 
Whenever you're using Twig, you'll see different delimiters being used.
 
::<b><nowiki>{{ something }}</nowiki></b> - You would use this to <b>display</b> (i.e., print or echo) the contents of "something."
 
::<b><nowiki>{% something %}</nowiki></b> - You would use this to <b>execute</b> something, typically to create conditions (e.g., <i>if</i> statements).
 
::<b><nowiki>{# something #}</nowiki></b> - This is a comment. Whatever you write between the hashes will not be displayed. These are handy to make notes for yourself or other admins inside emails and messages.
 
Here's how those would work in practice. If we sent this to a student named "John," they would receive the message on the right. Notice how the conditional text was handled, and that the comment wasn't shown.
 
<hr style='margin-bottom: 0px;'>
<div style='width: 49%; float: left;'>
<syntaxhighlight lang="twig">
Hi {{Student.First_Name}}!
 
{% if Student.First_Name == 'Jane' %}
    Your name is Jane.
{% else %}
    Your name is not Jane.
{% endif %}
 
{# I never said this example would be realistic #}
    </syntaxhighlight>
</div>
<div style='width: 49%; float: right;'>
    <blockquote style="margin-top: 15px;">
    Hi John!
 
    Your name is not Jane.
    </blockquote>
</div>
<hr>
<hr>
==Tags==
 
Email tags can be used to pull data from various TracCloud fields to be included in emails and upcoming appointments. Many of the Twig examples in this chapter will be using these tags, whether they’re used as part of a Twig command or just offhandedly included in an unrelated part of the email. A list of tags can be found at the bottom of this chapter (and within the TracCloud menu), but for a basic primer on how these tags can be used in isolation, here’s an example of a confirmation email.
Now here's a more realistic example.
<hr>
 
<nowiki>
<hr style='margin-bottom: 0px;'>
Hello,  {{Student.First_Name}}
<div style='width: 49%; float: left;'>
<br><br>
<syntaxhighlight lang="twig">
Your {{Appointment.OnlineText}} appointment with {{Consultant.FirstLast}} at
Hi {{Student.First_Name}},
{{Appointment.StartTime}} for {{Course.SubjectCourse}} has been scheduled. If you have any
 
questions prior to your appointment, feel free to reach out to {{Consultant.Email}}
Your appointment has been scheduled for {{Appointment.StartTime}} on {{Appointment.Day}}, {{Appointment.StartDate}} with {{Consultant.FirstLast}}.
<br><br>  
 
Your appointment can be joined here: {{Appointment.OnlineURL}}
{% if Appointment.Online == 1 %}
<br><br>
    Click here to join your appointment: {{Appointment.OnlineLink}}.</a>
Regards, {{Center.Name}}
{% endif %}
</nowiki>
</syntaxhighlight>
<hr>
</div>
When this email is sent, all the tags we included are replaced with the relevant information for this appointment.
<div style='width: 49%; float: right;'>
<br>
    <blockquote style="margin-top: 15px;">
[[File:76y5rgeth4j75k.png|500px]]
    Hi John,
 
    Your appointment has been scheduled for 04:00pm on Thursday, 04/02/26 with Dave Smith.
    </blockquote>
</div>
<hr>
<hr>


==if==
==Part 2. <i>if</i> Statements==
<i>if</i> statements will likely be the most commonly used Twig command for most use-cases. This allows you to write out statements such as <i>“if the student selected reason “Exam Help,then include this piece of text.</i> Or in the example below, <i>if the appointment is online, include text to specify this.</i>
 
<br><br>
The vast majority of the logic you're likely to build with Twig will be <i>if</i> statements. Simply, "if A, do X." You could also do "if A, do X. Otherwise if B, do Y. Otherwise if C, [...]" and so on. For a realistic example, "if the student selected the reason 'Exam Help,' then include the following paragraph" or "if the appointment is online, include the online meeting link."
In the statement, we’re using the same tags that are used for emails, but without the curly brackets.
 
<hr>
An <i>if</i> statement always begins with <nowiki>{% if [...] %}</nowiki> and ends with <nowiki>{% endif %}</nowiki>. When building emails and messages, you will be working with Twig tags (variables) in these statements. So the following...
<nowiki>
 
Hello {{Student.First_Name}},
<syntaxhighlight lang="twig">
<br><br>
{% if 2 > 1 %}
{% if Appointment.Online == "Online" %}
    two is greater than one!
This is an online appointment.
{% endif %}
 
{% if 1 == 1 %}
    1 is the same as 1!
{% endif %}
 
{% if "foo" != "bar" %}
    "foo" is a different word than "bar"!
{% endif %}
</syntaxhighlight>
 
...functions just like this. [[TracCloud:_Rosetta|Once again, a list of these tags and definitions are available here.]]
 
<syntaxhighlight lang="twig">
{% if Appointment.Online == 1 %}
    This is an online appointment, click the following to join....
{% endif %}
 
{% if Reason.ReasonName == "Writing Support" %}
    Please remember to upload your paper to your appointment. Here's how...
{% endif %}
</syntaxhighlight>
 
You can add <i>else</i> and <i>elseif</i> statements before the <i>endif</i> too, to handle alternate cases easily (rather than multiple separate <i>if...endif</i> statements for every condition).
 
<syntaxhighlight lang="twig">
{% if Appointment.Online == 1 %}
    Join Virtually: {{Appointment.OnlineLink}}
{% elseif Appointment.Online == 2 %}
    Accessing your Appointment: Login to TracCloud to view your asynchronous appointment.
{% elseif Appointment.Online == 3 %}
    We will call for your phone appointment at your chosen time.
{% else %}
    In-person location: {{Appointment.Location}}
{% else %}
</syntaxhighlight>
 
To check multiple conditions, <i>and</i> and <i>or</i> statements can be used.
 
<syntaxhighlight lang="twig">
{% if Reason.ReasonName == "Academic Coaching" and Student.WatchLists.wl_14 == 'true' %}
    Please remember to bring XYZ to this appointment.
{% endif %}
 
{% if Reason.ReasonName == "Peer Tutoring" or Consultant.CustomData.cf_123 == 'true' %}
    You have booked an appointment with a Peer Tutor!
{% endif %}
{% endif %}
<br><br>
</syntaxhighlight>
Please be ready for the appointment at the time you selected.
 
</nowiki>
A list of operators can be found in part 4.
 
==Part 3. Working with Arrays==
 
>95% of Twig tags you will work with in TracCloud contain single values, but a very small number of fields are <b>arrays</b> containing multiple values. Most notably, [[TracCloud:_SAGE|SAGE]] reasons & recommendations and Multiple Checkbox [[TracCloud:_Custom_Fields|custom fields]].
 
As an example, take Student.First_Name. This field can only contain one value at any given time. <i>Student.First_Name</i> = Jane, so <nowiki>{{Student.First_Name}}</nowiki> outputs Jane. But how about the <i>Reasons</i> field in SAGE referrals? This is an array that contains "Poor Grades" and "Acceptable Attendance" and "Lack of Focus." If we try to use <nowiki>{{Reasons}}</nowiki>, we'll get an error. That's where we have to take a slightly different approach, using the <i>for</i> tag.
 
Here's how this works, with an example variable so you can see what it's working with. For each item in the "exampleField" array, it prints the item (and adds a <nowiki><br></nowiki> tag to insert a line break).
 
<hr style='margin-bottom: 0px;'>
<div style='width: 49%; float: left;'>
<syntaxhighlight lang="twig">
{% set exampleField = ['a','b','c'] %}
   
{% for item in exampleField %}
    {{item}}<br>
{% endfor %}
</syntaxhighlight>
</div>
<div style='width: 49%; float: right;'>
    <blockquote style="margin-top: 15px;">
    a<br>
    b<br>
    c<br>
    </blockquote>
</div>
<hr>
<hr>
If the <i>if</i> statement is true, all text up to the endif line will be printed in the email. Since the appointment this student booked is online, the “This is an online appointment” text was included. Otherwise, it would jump straight to “Please be ready for the appointment…”
 
<br>
Now back to our SAGE example. Remember, Reasons is an array that contains ['Poor Grades','Acceptable Attendance','Lack of Focus'].
[[File:453j65ynh4g5rt.png|500px]]
 
<br><br>
<hr style='margin-bottom: 0px;'>
We aren’t limited to just “equals” either. Similar examples with different logic can be found below.
<div style='width: 49%; float: left;'>
<syntaxhighlight lang="twig">   
{% for item in Reasons %}
    {{item}}<br>
{% endfor %}
</syntaxhighlight><br>
</div>
<div style='width: 49%; float: right;'>
    <blockquote style="margin-top: 15px;">
    Poor Grades<br>
    Acceptable Attendance<br>
    Lack of Focus<br>
    </blockquote>
</div>
<hr>
<hr>
<nowiki>
 
{% if Course.Subject starts with "Chem" %}
You can also check if a value is in an array as an <i>if</i> statement like this. Inversely, you can do <i>not in</i> instead of <i>in</i> to check if a value is not in an array.
this text is only included if our subject starts with “Chem”. This is case-sensitive.  
 
<syntaxhighlight lang="twig">
{% if 'Poor Grades' in Reasons %}
    Here are some great resources to improve your study habits...
{% endif %}
{% endif %}


{% if Course.Subject ends with "101" %}
{% if "Meet with Advisor" in Recommendations %}
This text is only included if our subject ends with “101”
    We recommended that you meet with your advisor, here's how to schedule...
{% endif %}
{% endif %}
</syntaxhighlight>
More Twig examples and tag definitions for SAGE emails can be found [[TracCloud:_SAGE|here.]]
==Part 4. Tips and Tricks==
The remainder of this article covers some extra tips and tricks, as well as unique functions that may be of use.
===4.1. Special Tags===
TracCloud has a few special functions listed below that can be used to prevent an email from sending, CC additional recipients, automatically get special values, and more. More of these functions are available specifically for certain modules, such as [[TracCloud:_SAGE|SAGE Early Alerts]], [[TracCloud:_Success_Plans|Success Plans]], and [[TracCloud:_Work_Plans|Work Plans]]. Visit the emails/Twig sections of those articles to learn more. The ones listed below are available throughout TracCloud.
{| class="wikitable"
|-
| <nowiki>{{CalcMissedAppointments(Student.Sequence, Center.ProfileID)}}</nowiki> || The student's total number of missed appointments since the date specified in your profile Scheduling Prefs. Uses System Pref date if Profile date is blank.
|-
| <nowiki>{{CalcMissedDate(Center.ProfileID)}}</nowiki> || Your profile “Calc Missed Appointments Since” date. If this field is blank, this will use your global Calc Missed date instead.
|-
| <nowiki>{{setAdditionalCC('address@domain.edu,address2@domain.edu')}}</nowiki> || CC additional email addresses, can be used with 'if' statements to make the CC conditional.
|-
| <nowiki>{{ GetActiveTermFrom() }}</nowiki> || Can be used to get the start date of your current active term(s).
|-
| <nowiki>{{ GetActiveTermTo() }}</nowiki> || Can be used to get the end date of your current active term(s).
|-
| <nowiki>{{ setResultActions('SendEmail', '0') }}</nowiki> || Can be used to prevent an email from sending, similar to "#ACTION:DO NOT SEND#" in SAGE emails.
|-
| <nowiki>{{ GetDatePlusDays(5) }}</nowiki> || Get the current date plus the number of days specified in parentheses
|-
| <nowiki>{{ GetDateTimePlusDays(5) }}</nowiki> || Get the current date AND time plus the number of days specified in parentheses
|}
===4.2. List of Operators===
Beyond the basics like == (equals) and != (not equals), there are plenty more operators available depending on what you want to accomplish.
{| class="wikitable"
|-
! Operator !! Description !! True Example
|-
| == || Equals || <nowiki>{% if 1 == 1 %}</nowiki>
|-
| != || Does not equal || <nowiki>{% if 'a' != 'b' %}</nowiki>
|-
| > || Greater than || <nowiki>{% if 2 > 1 %}</nowiki>
|-
| < || Less than || <nowiki>{% if 1 < 2 %}</nowiki>
|-
| in || Is contained by (for arrays) || <nowiki>{% if 'a' in ['a','b','c'] %}</nowiki>
|-
| not in || Is not contained by (for arrays) || <nowiki>{% if 'z' not in ['a','b','c'] %}</nowiki>
|-
| starts with || Begins with || <nowiki>{% if 'abc' starts with 'a' %}</nowiki>
|-
| ends with || Concludes with || <nowiki>{% if 'abc' ends with 'c' %}</nowiki>
|-
|}
===4.3. Filters===
Filters can be used to modify or change the data stored in variables. One of the most common examples is using the 'date' filter to modify the format of dates in emails. For example, <nowiki>{{Appointment.StartDT}}</nowiki> would return 2026-01-31 14:00:00, while <nowiki>{{Appointment.StartDT|date("D, F j, h:ia")}}</nowiki> would return "Sat, January 31, 02:00pm." ([https://www.php.net/manual/en/datetime.format.php click here for a list of datetime format codes]). A list of some of the supported filters and functions in TracCloud can be found below.
{| class="wikitable"
|-
! Filter !! Description !! Example !! Output
|-
| date || Change the format of a date field || <nowiki>{{Appointment.StartDT|date("Y-m-d")}}</nowiki> || 2026-01-31
|-
| lower || Changes contents to lowercase || <nowiki>{{Student.First_Name|lower}}</nowiki> || jane
|-
| upper || Changes contents to uppercase || <nowiki>{{Student.First_Name|upper}}</nowiki> || JANE
|-
| trim || Trim spaces or text from the start and end of a string || <nowiki>{{Student.Email|trim('@example.edu')}}</nowiki> || jdoe
|}
===4.4. Indentation===
Twig is not indentation sensitive. Most of the examples in this article use indentation to improve readability, but it will function regardless of it. All three of the examples below will function identically.


{% if Appointment.Online != "Online" %}
<syntaxhighlight lang="twig">   
This text is only included if the appointment is not online
{% if Appointment.Online == 1 %}
    This is an online appointment!
{% endif %}
{% endif %}


{% if Course.Subject == "Math" or Course.Subject == "Chem" %}
{% if Appointment.Online == 1 %}
This text is only included if the subject is Math or Chem
This is an online appointment!
{% endif %}
{% endif %}


{% if (CalcMissedAppointments(Student.Sequence, Center.ProfileID) > 0) %}
{% if Appointment.Online == 1 %}This is an online appointment!{% endif %}
You have {{CalcMissedAppointments(Student.Sequence, Center.ProfileID)}} missed
</syntaxhighlight>
appointments since {{CalcMissedDate(Center.ProfileID)}}.
 
===4.5. Streamlining Twig Statements===
 
If you find yourself writing something like this:
 
<syntaxhighlight lang="twig">
{% if Reason.ReasonName == 'X' or Reason.ReasonName == 'Y' or Reason.ReasonName == 'Z' %}
</syntaxhighlight>
 
Try using an array instead. Both will work, but the latter is cleaner and easier to update later.
 
<syntaxhighlight lang="twig">
{% if Reason.ReasonName in ['X','Y','Z'] %}
</syntaxhighlight>
 
<hr>
 
If you're repeatedly checking the same condition, like this:
 
<syntaxhighlight lang="twig">
Your {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} online {% endif %} appointment has been scheduled for...
Location: {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} To join, please click... {% endif %}...
Appointment policies: {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} Please remember to... {% endif %}...
</syntaxhighlight>
 
Consider setting a variable once and using that instead:
 
<syntaxhighlight lang="twig">
{% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %}
    {% set online = true %}
{% else %}
    {% set online = false %}
{% endif %}
{% endif %}
</nowiki>
 
Your {% if online %} online {% endif %} appointment has been scheduled for...
Location: {% if online %} To join, please click... {% endif %}...
Appointment policies: {% if online %} Please remember to... {% endif %}...
</syntaxhighlight>
 
<hr>
<hr>


This one is more minor, but in most cases instead of writing this:


|}
<syntaxhighlight lang="twig">
{{DISPLAYTITLE:<span style="position: absolute; clip: rect(1px 1px 1px 1px); clip: rect(1px, 1px, 1px, 1px);">{{FULLPAGENAME}}</span>}}
{% if Appointment.Location != '' %}
</syntaxhighlight>
 
You can write the following. This will return true if that field is not false, blank, or 0.
 
<syntaxhighlight lang="twig">
{% if Appointment.Location %}
</syntaxhighlight>
 
==Part 5. Getting Help==
 
If you're a primary SysAdmin for your TracCloud instance and you need some help with Twig or HTML, feel free to reach out to us. Scroll all the way to the top of this page and click the "Support" tab to visit our helpdesk.
 
[[Category:TracCloud Manual]]
</div>

Latest revision as of 15:08, 8 April 2026

TracCloud Twig Guide

Many text fields throughout TracCloud support Twig and HTML, giving you greater control in determining what data is displayed to your students, staff, and faculty based on the context of appointments, visits, and more, as well as formatting that data to be as clear as possible.

Twig will be the primary focus of this article. Twig is a template engine that serves two primary purposes in TracCloud:

  • 1. Print variables in text
Personalize your emails and messages. Greet the student by name, let them know what subject they selected in their appointment, what time their appointment takes place, the location, and more. These same variables are also used for purpose #2.
  • 2. Add logic to your text
Modify the email or message based on why it was sent. Add an extra paragraph if Reason X was selected, send a follow-up email after a visit if the student chose Y, prevent an email from being sent on a SAGE referral if Z recommendation was checked, and much more. Rather than creating a generic email for any context, create a dynamic email that changes to match your needs.

Twig (and HTML) are supported in profile emails, welcome messages, email templates, appointment display, and more. Most of the examples listed in this article are for appointment emails or SAGE referrals, but the same concepts apply in all other supported fields. It's also worth keeping in mind that Twig exists outside of TracCloud, and there are many resources online for how you can utilize it that will also work here (such as Symfony). This guide likely covers everything you will need, but it doesn't cover everything that Twig is capable of.

HTML will also be used sparingly throughout this article, but without much explanation as it's more ubiquitous than Twig. There are many excellent resources online explaining how to use this markup language, such as W3Schools. HTML is used to adjust font sizes and colors, embed images and videos, and more.

Part 1. Syntax, Terminology, and Essential Knowledge

When reading the wiki or talking to support, you will often see fields like Student.First_Name or Courses.Subject referred to as "Twig tags." To use another term, these are variables. They contain data, it's up to you what you do with that data through Twig. If you're at all familiar with any programming languages, then you likely already know the concepts. This article will provide you with the necessary knowledge to use Twig in TracCloud, regardless of your current knowledge level.

Important: A complete list of Twig tags can be found here. Not all tags can be used in all places, but you can almost always predict what will and won't work in a given location. For example, in the Appointment Confirmation Email, you can expect to use Student, Reason, Subject, Staff tags, etc. Whereas in the Notices on KIOSK, you can only use Center tags. This is because when that message is displayed at the top of an idle kiosk, nothing ties that message to any one Student or Staff record, let alone Registrations, Reasons, etc.

Whenever you're using Twig, you'll see different delimiters being used.

{{ something }} - You would use this to display (i.e., print or echo) the contents of "something."
{% something %} - You would use this to execute something, typically to create conditions (e.g., if statements).
{# something #} - This is a comment. Whatever you write between the hashes will not be displayed. These are handy to make notes for yourself or other admins inside emails and messages.

Here's how those would work in practice. If we sent this to a student named "John," they would receive the message on the right. Notice how the conditional text was handled, and that the comment wasn't shown.


Hi {{Student.First_Name}}!

{% if Student.First_Name == 'Jane' %} 
    Your name is Jane.
{% else %}
    Your name is not Jane.
{% endif %}

{# I never said this example would be realistic #}

Hi John!

Your name is not Jane.


Now here's a more realistic example.


Hi {{Student.First_Name}},

Your appointment has been scheduled for {{Appointment.StartTime}} on {{Appointment.Day}}, {{Appointment.StartDate}} with {{Consultant.FirstLast}}.

{% if Appointment.Online == 1 %}
    Click here to join your appointment: {{Appointment.OnlineLink}}.
{% endif %}

Hi John,

Your appointment has been scheduled for 04:00pm on Thursday, 04/02/26 with Dave Smith.


Part 2. if Statements

The vast majority of the logic you're likely to build with Twig will be if statements. Simply, "if A, do X." You could also do "if A, do X. Otherwise if B, do Y. Otherwise if C, [...]" and so on. For a realistic example, "if the student selected the reason 'Exam Help,' then include the following paragraph" or "if the appointment is online, include the online meeting link."

An if statement always begins with {% if [...] %} and ends with {% endif %}. When building emails and messages, you will be working with Twig tags (variables) in these statements. So the following...

{% if 2 > 1 %}
    two is greater than one!
{% endif %}

{% if 1 == 1 %}
    1 is the same as 1!
{% endif %}

{% if "foo" != "bar" %}
    "foo" is a different word than "bar"!
{% endif %}

...functions just like this. Once again, a list of these tags and definitions are available here.

{% if Appointment.Online == 1 %}
    This is an online appointment, click the following to join....
{% endif %}

{% if Reason.ReasonName == "Writing Support" %}
    Please remember to upload your paper to your appointment. Here's how...
{% endif %}

You can add else and elseif statements before the endif too, to handle alternate cases easily (rather than multiple separate if...endif statements for every condition).

{% if Appointment.Online == 1 %}
    Join Virtually: {{Appointment.OnlineLink}}
{% elseif Appointment.Online == 2 %}
    Accessing your Appointment: Login to TracCloud to view your asynchronous appointment.
{% elseif Appointment.Online == 3 %}
    We will call for your phone appointment at your chosen time.
{% else %}
    In-person location: {{Appointment.Location}}
{% else %}

To check multiple conditions, and and or statements can be used.

{% if Reason.ReasonName == "Academic Coaching" and Student.WatchLists.wl_14 == 'true' %}
    Please remember to bring XYZ to this appointment.
{% endif %}

{% if Reason.ReasonName == "Peer Tutoring" or Consultant.CustomData.cf_123 == 'true' %}
    You have booked an appointment with a Peer Tutor!
{% endif %}

A list of operators can be found in part 4.

Part 3. Working with Arrays

>95% of Twig tags you will work with in TracCloud contain single values, but a very small number of fields are arrays containing multiple values. Most notably, SAGE reasons & recommendations and Multiple Checkbox custom fields.

As an example, take Student.First_Name. This field can only contain one value at any given time. Student.First_Name = Jane, so {{Student.First_Name}} outputs Jane. But how about the Reasons field in SAGE referrals? This is an array that contains "Poor Grades" and "Acceptable Attendance" and "Lack of Focus." If we try to use {{Reasons}}, we'll get an error. That's where we have to take a slightly different approach, using the for tag.

Here's how this works, with an example variable so you can see what it's working with. For each item in the "exampleField" array, it prints the item (and adds a <br> tag to insert a line break).


{% set exampleField = ['a','b','c'] %}
    
{% for item in exampleField %}
    {{item}}<br>
{% endfor %}

a
b
c


Now back to our SAGE example. Remember, Reasons is an array that contains ['Poor Grades','Acceptable Attendance','Lack of Focus'].


    
{% for item in Reasons %}
    {{item}}<br>
{% endfor %}

Poor Grades
Acceptable Attendance
Lack of Focus


You can also check if a value is in an array as an if statement like this. Inversely, you can do not in instead of in to check if a value is not in an array.

{% if 'Poor Grades' in Reasons %}
    Here are some great resources to improve your study habits...
{% endif %}

{% if "Meet with Advisor" in Recommendations %}
    We recommended that you meet with your advisor, here's how to schedule...
{% endif %}

More Twig examples and tag definitions for SAGE emails can be found here.

Part 4. Tips and Tricks

The remainder of this article covers some extra tips and tricks, as well as unique functions that may be of use.

4.1. Special Tags

TracCloud has a few special functions listed below that can be used to prevent an email from sending, CC additional recipients, automatically get special values, and more. More of these functions are available specifically for certain modules, such as SAGE Early Alerts, Success Plans, and Work Plans. Visit the emails/Twig sections of those articles to learn more. The ones listed below are available throughout TracCloud.

{{CalcMissedAppointments(Student.Sequence, Center.ProfileID)}} The student's total number of missed appointments since the date specified in your profile Scheduling Prefs. Uses System Pref date if Profile date is blank.
{{CalcMissedDate(Center.ProfileID)}} Your profile “Calc Missed Appointments Since” date. If this field is blank, this will use your global Calc Missed date instead.
{{setAdditionalCC('address@domain.edu,address2@domain.edu')}} CC additional email addresses, can be used with 'if' statements to make the CC conditional.
{{ GetActiveTermFrom() }} Can be used to get the start date of your current active term(s).
{{ GetActiveTermTo() }} Can be used to get the end date of your current active term(s).
{{ setResultActions('SendEmail', '0') }} Can be used to prevent an email from sending, similar to "#ACTION:DO NOT SEND#" in SAGE emails.
{{ GetDatePlusDays(5) }} Get the current date plus the number of days specified in parentheses
{{ GetDateTimePlusDays(5) }} Get the current date AND time plus the number of days specified in parentheses

4.2. List of Operators

Beyond the basics like == (equals) and != (not equals), there are plenty more operators available depending on what you want to accomplish.

Operator Description True Example
== Equals {% if 1 == 1 %}
!= Does not equal {% if 'a' != 'b' %}
> Greater than {% if 2 > 1 %}
< Less than {% if 1 < 2 %}
in Is contained by (for arrays) {% if 'a' in ['a','b','c'] %}
not in Is not contained by (for arrays) {% if 'z' not in ['a','b','c'] %}
starts with Begins with {% if 'abc' starts with 'a' %}
ends with Concludes with {% if 'abc' ends with 'c' %}

4.3. Filters

Filters can be used to modify or change the data stored in variables. One of the most common examples is using the 'date' filter to modify the format of dates in emails. For example, {{Appointment.StartDT}} would return 2026-01-31 14:00:00, while {{Appointment.StartDT|date("D, F j, h:ia")}} would return "Sat, January 31, 02:00pm." (click here for a list of datetime format codes). A list of some of the supported filters and functions in TracCloud can be found below.

Filter Description Example Output
date Change the format of a date field {{Appointment.StartDT|date("Y-m-d")}} 2026-01-31
lower Changes contents to lowercase {{Student.First_Name|lower}} jane
upper Changes contents to uppercase {{Student.First_Name|upper}} JANE
trim Trim spaces or text from the start and end of a string {{Student.Email|trim('@example.edu')}} jdoe

4.4. Indentation

Twig is not indentation sensitive. Most of the examples in this article use indentation to improve readability, but it will function regardless of it. All three of the examples below will function identically.

    
{% if Appointment.Online == 1 %}
    This is an online appointment!
{% endif %}

{% if Appointment.Online == 1 %}
This is an online appointment!
{% endif %}

{% if Appointment.Online == 1 %}This is an online appointment!{% endif %}

4.5. Streamlining Twig Statements

If you find yourself writing something like this:

{% if Reason.ReasonName == 'X' or Reason.ReasonName == 'Y' or Reason.ReasonName == 'Z' %}

Try using an array instead. Both will work, but the latter is cleaner and easier to update later.

{% if Reason.ReasonName in ['X','Y','Z'] %}

If you're repeatedly checking the same condition, like this:

Your {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} online {% endif %} appointment has been scheduled for... 
Location: {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} To join, please click... {% endif %}... 
Appointment policies: {% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %} Please remember to... {% endif %}...

Consider setting a variable once and using that instead:

{% if Appointment.Online == '1' or Appointment.CustomData.cf_123 == 'Hybrid Appt' %}
    {% set online = true %}
{% else %}
    {% set online = false %}
{% endif %}

Your {% if online %} online {% endif %} appointment has been scheduled for... 
Location: {% if online %} To join, please click... {% endif %}... 
Appointment policies: {% if online %} Please remember to... {% endif %}...

This one is more minor, but in most cases instead of writing this:

{% if Appointment.Location != '' %}

You can write the following. This will return true if that field is not false, blank, or 0.

{% if Appointment.Location %}

Part 5. Getting Help

If you're a primary SysAdmin for your TracCloud instance and you need some help with Twig or HTML, feel free to reach out to us. Scroll all the way to the top of this page and click the "Support" tab to visit our helpdesk.