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" ??
An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters. A null string is represented by null .
You can use the IsNullOrWhiteSpace method to test whether a string is null , its value is String. Empty, or it consists only of white-space characters.
An empty string is a String object with an assigned value, but its length is equal to zero. A null string has no value at all. A blank String contains only whitespaces, are is neither empty nor null , since it does have an assigned value, and isn't of 0 length.
Liquid objects can return one of seven basic types: String, Number, Boolean, Array, Dictionary, DateTime, or Null.
After discussion in comments, it was a simple logic mistake.
{% if MyString != null and MyString != "" %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With