Created
February 16, 2018 22:07
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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