A lot of template development involves checking that something “exists.” This question is weirdly deep and existential, so we’re going to start off as simple as possible, then dig deeper.
- When checking strings, compare against
blank
- When checking collections, compare against
empty
- When checking anything else, use standard comparison operators
Why does it get any weirder than that? Because “exists” could mean a lot different things, and even more when you don’t know what the value type you’re comparing is. To say something “exists” could mean:
- That a value of any kind is in the Context
- That the value is not
null
- If it’s a boolean, that the value is
true
- That text is not empty or whitespace
- That a number is above 0
- That a collection has at least one element
- That a date is not the default date (
DateTime.MinValue
)
To dig a little deeper, we’ll discuss how the conditionals actually perform, then we’ll dig into the theory behind it and how you can change it if you like. Fluid gives your some wonderful customization options to make conditional logic as easy as possible to your template developers.
Let’s start by assuming name
is text (a StringValue
).
Just doing this will check if it is in the Context.