DotLiquid - checking for string "null or empty"

marc_s picture marc_s · Feb 27, 2015 · Viewed 12.4k times · Source

I'm using DotLiquid for some e-mail templates in my ASP.NET 4.0 Webforms app, and I'm trying to exclude a certain section of one of my e-mail templates if a given string in the data object I bind to the template is null or empty.

Checking for NULL works quite nicely:

{% if MyString != null %}

Some fancy label: {{ MyString }}
{% endif %}";

However, whatever I've tried to also include the empty string in this test has failed so far:

{% if MyString != null or MyString == empty %}

{% if MyString != null or MyString == '' %}

How can I check for "if this string is null or empty" ??

Answer

Der Kommissar picture Der Kommissar · Feb 27, 2015

After discussion in comments, it was a simple logic mistake.

{% if MyString != null and MyString != "" %}