Skip to content

Instantly share code, notes, and snippets.

@brennandunn
Last active February 1, 2022 12:58
Show Gist options
  • Save brennandunn/7e0948d4456b93df9feefbcf1946d999 to your computer and use it in GitHub Desktop.
Save brennandunn/7e0948d4456b93df9feefbcf1946d999 to your computer and use it in GitHub Desktop.
{%- capture output -%}
{% assign salutations = "Hey< X>,/ Hi there<, X>,/ Hola< X>,/ What's going on<, X>?/ Hi< X>!" %}
{% assign salutations_array = salutations | split: '/' %}
{% assign salutations_length = salutations_array | size %}
{% assign random = "now" | date: "%9N" | modulo: salutations_length %}
{% assign template = salutations_array[random] %}
{% assign formatted_name = subscriber.first_name | split: " " | first | capitalize %}
{% if subscriber.first_name != "" %}
{% assign template = template | replace: "<", "" | replace: ">", "" %}
{% assign template = template | replace: "X", formatted_name %}
{% else %}
{% assign first_bit = template | split: "<" | first %}
{% assign last_bit = template | split: ">" | last %}
{% assign template = first_bit | append: last_bit %}
{% endif %}
{%- endcapture -%}
{{ template | strip_html | strip }}
@erikdkennedy
Copy link

A tip for others – if you get the "Invalid Liquid" error from ConvertKit, try pressing "Raw" above and copying the plaintext code. That does the trick 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment