Loading...

How to check if a string is blank in Liquid?

question liquid
Ram Patra Published on August 11, 2020
Liquid Version - 4.0.3

I read the official docs of Liquid but couldn’t find the info that I was looking for.

In the end, the below code worked for me:

{% if string != nil and string != "" %}
    Do whatever with string
{% endif %}

Example code:

{% assign name="Blog" %}
{% if name != nil and name != "" %}
    Yay!
{% else %}
    Nay
{% endif %}

Output:

Yay!
Presentify

Take your presentation to the next level.

FaceScreen

Put your face and name on your screen.

ToDoBar

Your to-dos on your menu bar.

Ram Patra Published on August 11, 2020
Image placeholder

Keep reading

If this article was helpful, others might be too

question liquid August 11, 2020 How to create an array in Liquid?

The official doc of Liquid doesn’t tell us a way tocreate an array except this:

question liquid jekyll August 11, 2020 How to escape Liquid template code in a Jekyll website?

We know that Jekyll uses Liquid as its templating language. This means all your Liquid code will be executed by Jekyllby default.