Skip to content

Instantly share code, notes, and snippets.

@letrastudio
Created February 16, 2018 22:07
Show Gist options
  • Save letrastudio/2417657ea0b18ca1604be2a31bcfc31c to your computer and use it in GitHub Desktop.
Save letrastudio/2417657ea0b18ca1604be2a31bcfc31c to your computer and use it in GitHub Desktop.
Detect the type of a Liquid object https://shopify.github.io/liquid/basics/types/
{% if object == nil %}
object is nil
{% elsif object == true or object == false %}
object is a boolean
{% elsif object.first %}
object is an array
{% else %}
{% assign number_test = object | divided_by: 1.0 %}
{% if object == number_test %}
object is a number
{% assign object_string = object | downcase %}
{% assign number_test_string = number_test | downcase %}
{% if object_string == number_test_string %}
number is a float
{% else %}
number is an integer
{% endif %}
{% else %}
object is a string
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment