Fundamental Liquid Markup and Conditional Logic
  • 17 May 2024
  • 4 minute read
  • Dark
    Light
  • PDF

Fundamental Liquid Markup and Conditional Logic

  • Dark
    Light
  • PDF

Article Summary

The Deliver tool features two tools to display text in a message conditionally. The first, conditional logic, can be accessed by clicking the if icon. To use conditional logic:

  1. Highlight the text to be conditionally displayed.

  2. Click the if icon.

  3. Specify the conditions for showing the text.

  4. Click Ok.

While conditional logic is useful for making simple comparisons, Liquid markup excels at simple to complex comparisons that show/hide a few words to entire paragraphs and even images.

Something to also note is that there is a slight variation in how conditional logic and Liquid markup appear when viewing the message:

liquid.png

You can update evaluations by double-clicking on the highlighted statements. However, we recommend writing and editing directly in the message's source for Liquid markup. This will allow for more complex evaluations and easier upkeep.

Tip

Liquid markup cannot parse ampersands in strings. Using special characters like "&" should be avoided if possible.

Making Comparisons with Tags

Use Liquid markup to compare a merge field against a static value or another merge field to show information conditionally. Evaluations are initiated with the if tag and closed with the endif tag:

{% if {{major}} == 'Philosophy' %}Existentialism? Don't get us started!{% endif %}

The elsif tag allows for multiple comparisons:

{% if {{major}} == 'Philosophy' %}Existentialism? Don't get us started!{% elsif {{major}} == 'Biology' %}It's in our genetics to drift toward academic excellence!{% endif %}

The else tag will return a value if all prior evaluations were FALSE. This is useful when displaying a generic message:

{% if {{major}} == 'Philosophy' %}Existentialism? Don't get us started!{% elsif {{major}} == 'Biology' %}It's in our genetics to drift toward academic excellence! {% else %}We support you in your academic pursuits!{% endif %}

Tags

Function

Example(s)

assign

Assigns a value to a variable

{% assign missing_items = {{Missing-Checklist-Items}} | split: "|" %}

capture

Captures and assigns a value to a variable

{% capture team %}{{sex}}'s {{sport}} {% endcapture %}

case

An efficient method of comparing a variable against multiple conditions

{% case {{major}} %}{% when 'Philosophy' %}Existentialism? Don't get us started!{% when 'Biology' %}It's in our genetics to drift toward academic excellence!{% else %}We support you in your academic pursuits!{% endcase %}

for

Loops through a range, which can be an array

{% for interest in academic_interest %}{{interest}}{% endfor %}

if/elsif

Determines if one value is equal to another value

{% if {{major}} == 'Philosophy' %}Existentialism? Don't get us started!{% elsif {{major}} == 'Biology' %}It's in our genetics to drift toward academic excellence!{% endif %}

unless

Reverse of an if statement

{% unless {{major}} != 'Quantum Physics' %}Achieving an A is probable.{% endunless %}

Comparison Operators

You can make different kinds of comparisons by adjusting the operator:

Comparison Operators

Function

Example(s)

==

Determines if one value is equal to another value

{% if {{major}} == 'Philosophy' %}Existentialism? Don't get us started!{% endif %}

!=

Determines if one value is not equal to another value

{% if {{major}} != 'Statistics' %}Probability is overrated!{% endif %}

>, >=, <, <=

Determines if one value is:

  • >=, greater than or equal to

  • >, greater than

  • <, less than

  • <=, less than or equal to another value

{% if {{guests}} >= 10 %}Groups of 10 or more will need to ride in separate golf carts.{% endif %}

{% if {{guests}} > 10 %}Groups of more than 10 will need to ride in separate golf carts.{% endif %}

{% if {{guests}} < 10 %}Groups of less than 10 will ride in the same golf cart.{% endif %}

{% if {{guests}} <= 9 %}Groups of nine or less will ride in the same golf cart.{% endif %}

contains

Determines if one value contains another value

{% if {{major}} contains 'Science' %}Let us tell you more about the seduction of scientific deduction!{% endif %}

Boolean Operators

Multiple comparisons can be made in the same evaluation using the and & or Boolean operators:

Boolean Operators

Function

Example(s)

 and

Determines if both comparisons are true

{% if {{major}} == 'Philosophy' and {{degree}} == 'Doctorate' %}So we take it you're serious about Philosophy?{% endif %}

 or

Determines if one or both comparisons are true

 {% if {{major}} == 'Philosophy' or {{major}} == 'Political Science' %}Debate is in your future{% endif %}

Standard Filters

Standard filters allow you to modify content in merge fields:

Standard Filters

Function

Example(s)

date

Formats a date

{{form-date | date: 'MMMM d, yyyy' }}

divided_by

Divides two numbers

{{registration_limit | divided_by: registrants }}

downcase

Sets all letters to lowercase

{{first | downcase }}

first

Returns the first element of an array

{{academic_interests | first }}

last

Returns the last element of an array

{{academic_interests | last }}

map

Returns only the specified elements in an array

{{scholarships | map: 'names'}}

minus

Subtracts two numbers

{{registration_limit | minus: registrants }}

modulo

Returns the remainder after division

{{4 | modulo: 2 }}

plus

Adds two numbers

{{registrants | plus: waitlist }}

replace_first

Replaces the first occurrence of a match

{{sisID | replace_first:'Slate-', '' }}

size

Returns the number of elements in an array or the number of characters in a string

{{academic_interests | size}}

{{academic_interests.size}}

snippet

Allow you to pass in a value and output a content block.

{{ program | snippet: "program_long_description" }}

split

Splits a string into an array on a matching criteria

{{ academic_interests | split: "|" }}

strip_html

Removes HTML tags from a string

{{ academic_interests | strip_html }}

times

Multiples two numbers

{{courses | times: 550 }}

uniq

Dedupes values in an array

{{ academic_interests_array | uniq }}

upcase

Sets all letters to uppercase

{{ first | upcase }}

Helper Variables

Helper variables are useful for assessing properties of a for loop:

Helper Variable

Function

forloop.length

Length of the loop

forloop.index

Number of current loop iteration

forloop.rindex

Number of remaining loop iteration(s)

forloop.first

Determines if the current iteration is the first iteration

forloop.last

Determines if the current iteration is the last iteration


Was this article helpful?