Skip to main content

Moustache Templates/Variables Guide

Learn how Moustache Templates & Variables work here.

Written by Maahi Islam
Updated over 2 weeks ago

Moustache Templates Guide

Example

Function

Description

########{{ name_of_variable }}

Insert variable

This is how we insert variables into template. For instance, `` will pull in the first name of the person you are sending the email to.

########{{#variable_to_check}} ... ########{{\variable_to_check}}

IF statement

This adds logic to the template. If the variable exists or is true, then the text in the middle of it will be inserted into the template. If the variable doesn't exist or is not true, then the text will not be included.

########{{^variable_to_check}} ... ########{{\variable_to_check}}

IF NOT statement

This does the opposite of the line above. If the variable doesn't exist or is not true, then the text will be included, and vice versa.

Frequently Asked Questions

Why aren't my variables working?

Even if you have entered the right variable for a particular field, it may be the case that these aren't being reflected on the emails themselves. The reason for this may be that you have yet to frame these variables. Framing your variables is sometimes necessary in order to tell the system what it should be looking for. For example; if you were attempting to write a Job Confirmation Email to your Tutors, you may wish to let Tutors know what the Student's details are (name, address, their associated Client, phone number, etc.). However, when taken alone, entering the variable ########{{ client_name }} will not return any results, because the system requires context within which to search for that information.

The way to provide this much-needed context is through "nesting" your variables, here's a quick run-through, using the example above as our guide.

  • In this example, we would want to nest our variable ########{{ client_name }} within a variable which tells the system that you are looking for the details of that particular Student (a.k.a. Service Recipient).

  • How would we tell the system this? Simply by adding another variable before, in this case, that would be: ########{{ #student_recipient_details }}

  • Now that we have told the system to look for these ########{{ #student_recipient_details }}, it will come to the variable for ########{{ client_name }} and know exactly what it needs to look for, but what happens after that?

  • If left like this, the system will continue to look for the Student's details for every other variable on the page, which is not what we want, so in order to structure our email properly, we will need to tell it to stop looking for the Student's details at some point as well.

  • The way we do this is by writing another new variable, below ########{{ client_name }} which tells it to stop, this is written as ########{{ /student_recipient_details }}

  • Now the system knows where to start looking for the correct information: ########{{ #student_recipient_details }}

  • Where to look specifically for the information: ########{{ client_name }}

  • And when to stop looking for the correct information: ########{{ /student_recipient_details }}

  • This is how you nest your variables in order to keep them functioning properly.

What nested variables can I use?

As described above, nesting variables is the way to tell TutorCruncher what type of variables it should be looking for in a given Email Definition. This initial, or Primary Variable, sets the context for the rest of the variables, we can call them Secondary Variables, which are "nested" inside the opening and closing parts of our Primary Variable. So, if a Primary Variable establishes the context, and the Secondary Variables come within that Primary variable, how do you know which is which?

You can identify these different kinds of variables on TutorCruncher by going to your Email Definitions, editing a given email and scrolling down to the list of Available Variables. Secondary Variables will be listed below their corresponding primary variable, indented to the right and filtered grey.

This is an example of the Nested Variables which correspond to the primary variable ####{{ #student_recipient details }} - As per the example given above.

This is an example of the Nested Variables which correspond to the Primary Variable ########{{ #student_recipient details }} as per the example given above.

Note:

  • The logical parts of the template, the IF and IF NOT statements, must be opened and closed for the template to work. For instance, you cannot simply do ########{{#variable_to_check}} ..., you also include ########{{\variable_to_check}}.
    ​

  • If you have inserted the first part of an IF or IF NOT statement, the opening part, then you must include the second part, the closing part, before you close another. For instance, the following will not work:

########{{#first_variable_to_check}} < Opening first IF statement...########{{#second_variable_to_check}} < Opening second IF statement...########{{/first_variable_to_check}} < Closing first IF statement...########{{/second_variable_to_check}} < Closing second IF statement

Whereas this would:

########{{#first_variable_to_check}} < Opening first IF statement...########{{#second_variable_to_check}} < Opening second IF statement...########{{/second_variable_to_check}} < Closing second IF statement...########{{/first_variable_to_check}} < Closing first IF statement
Did this answer your question?