Search code examples
c#asp.netdotliquid

DotLiquid - checking for string "null or empty"


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" ??


Solution

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

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