SchoolAdmin uses the template language Liquid created by Shopify that is designed for quickly developing dynamic content. Designed for accessibility by non-programmers, it allows users to create basic, easy to read statements that when evaluated, display certain data based on if / else statements.  Below is a subset of the documentation with the most common examples schools may look to use.

For more documentation, please visit: https://shopify.github.io/liquid/

If you ever need help, please let us know.  If you never learn to use Liquid, that is ok, just be aware that it exists and the core it enables highly dynamic and personalized content to be placed in your forms, emails, and letter templates.  It can also be used to create custom content in the parent portal or display information on contact records.

Using If / Else Statements

if / else statements should be familiar from other programming languages. Liquid implements them with the following tags:

  • {% if <CONDITION> %} … {% endif %}Encloses a section of template which will only be run if the condition is true.
  • {% elsif <CONDITION> %}Can optionally be used within an if … endif block. Specifies another condition; if the initial “if” fails, Liquid tries the “elsif”, and runs the following section of template if it succeeds. You can use any number of elsifs in an ifblock.
  • {% else %}Can optionally be used within an if … endif block, after any “elsif” tags. If all preceding conditions fail, Liquid will run the section of template following the “else” tag.
  • {% unless <CONDITION> %} … {% endunless %}The reverse of an “if” statement. Don’t use “elsif” or “else” with an unless statement.

The condition of an if, elsif or unless tag should be either a normal Liquid expression or a comparison using Liquid expressions. Note that the comparison operators are implemented by the “if”-like tags; they don’t work anywhere else in Liquid.

The available comparison operators are:

  • ==, !=, and <>equality and inequality (the latter two are synonyms)There’s a secret special value empty (unquoted) that you can compare arrays to; the comparison is true if the array has no members.
  • <, <=, >, >=less/greater-than
  • containsa wrapper around Ruby’s include? method, which is implemented on strings, arrays, and hashes. If the left argument is a string and the right isn’t, it stringifies the right.

The available Boolean operators are:

  • and
  • or

Note that there is NO “not” operator. Also note that you CANNOT use parentheses to control order of operations, and the precedence of the operators appears to be unspecified. So when in doubt, use nested “if” statements instead of risking it.

Liquid Examples

Boolean Fields

For boolean you can evaluate on three values:  true (aka yes), false (aka no), and empty (aka nil).

Shows text only if the boolean field is set to True

{% if contact.international =='true' %}International Student{% endif %}

Shows No if the value is No or Nil (blank), otherwise shows Yes

{% if contact.field_yn !='true' %}No{% else %}Yes{% endif %}

ONLY shows a value for No or Yes.  Nil (blank values are ignored and don’t show anything. This is good when you want to be explicit about the Yes / No choice made and don’t want to show No if the value has been left blank

{% if contact.international =='true' %}YES{% endif %}{% if contact.international =='false' %}NO{% endif %}

Shows text only if the field doesn’t have an answer (aka empty)

{% if contact.international =='' %}NO VALUE SELECTED{% endif %}

Single Selects

The main difference with Single Selects from Boolean fields is that you have to explicitly declare the value.  If the single select has Yes and No for values, you have to use ‘Yes’ or ‘No’ rather than true / false.  Generally, statements will look very similar to Boolean fields but there are some additional use cases because the list of values can be more varied.  In these cases, making use of AND / OR may provide useful.

OR example

{% if contact.state =='VA' OR contact.state =='DC' %}In Service Area{% else %}Outside of Service Area{% endif %}

Combining two different field values to create an output

This statements the values from two different fields and if both values are true, it displays a value.

{% if contact.field1_ss =='blue' AND contact.field2_ss =='yellow' %}GREEN{% endif %}

Similar to above, but with an added ifelse & else statement. 

{% if contact.color_ss =='blue' AND contact.color2_ss =='yellow' %}GREEN
{% elsif contact.color_ss =='red' AND contact.color2_ss =='yellow'%}Orange
{% else %}ALL IS GRAY
{% endif %}

To break this statement is apart we have a single field “color”. If the selected values are blue & yellow, the displayed text is green. If the values are red & yellow, the displayed text is orange. If neither combination is true, then all is gray.

Here is an example of calculating whether a student is old enough to enroll in Kindergarten and displaying that on a contact record.  If the contact isn’t applying for the K grade, then this statement will not show anything.

{% if contact.grade =='K' AND contact.entry_age_month >='60' %}Eligible for Kindergarten{% endif %}

For Multi-Selects

Multi-selects are stored in a manner which requires the use of the contains argument rather than ==

Example:
{% if contact.color_ms contains 'blue' AND contact.color_ms contains 'yellow' %}GREEN
{% elsif contact.color_ms contains 'red' AND contact.color_ms contains'yellow'%}Orange
{% else %}ALL IS GRAY
{% endif %}

This statement is similar to the above example but using a single multiple select rather than 2 different single selects.

Showing different statements depending on contact role, status, other data.

It is common to only want to show certain information based on the contact’s role or status.  To do this, you wrap all the fields that you want to contextually show inside an if statement.

For example:

{% if contact.role == 'inquiry' %}

Liquid statements you want to only show if role equals inquiry

{% endif %}

Examples

Inquiry

{% if contact.role == 'inquiry' %}

Referral Method: {{contact.referral_method}}

Academic Interest: {{contact.academic_interest}}

{% if contact.sibling_at_school =='true' %}Sibling Attends School{% endif %}
{% if contact.parent_alumni =='true' %}Child of Alumni (Legacy){% endif %}
{% endif %}

International Applicant

{% if contact.is_international_student == 'true' AND contact.role == 'applicant'%}

International Student

Requires F1 Sponsorship: {{contact.requires_sponsorship}}

Working with Agency: {{contact.agency}}

{% if contact.agency =='true' %}

Agent Name: {{contact.agent_name}}

Agency Name: {{contact.agency_name}}

Agent Email: {{contact.agent_email}}

Agent Phone: {{contact.agent_phone}}

{% endif %}
{% endif %}

To break the above statement down, if the contact has the role applicant and Is International Student option is true (aka yes), then show the enclosed set of information.  Otherwise, nothing will appear.  The information shown is a mix of plain text and dynamic information based on whether the family is working with an agent.

General purpose Liquid Statements

Show today’s date:

{{ ‘now’ | date: “%D” }}

Troubleshooting Tips

  • If you are formatting liquid statement (for example, bolding or making a color), make sure the formatting is outside the liquid statement brackets {}
  • In a more complex statements, break down the components and test them independently to ensure the argument is returning the expected value.
Did this answer your question?