I haven’t tracked this down in the source code yet, so I’m just describing a behavior. It’s inconsistent behavior, at best, but more likely a bug. I also haven’t checked to see if it’s fixed in 5.0 yet.
When creating a template view backed by a model, null model sub-properties aren’t handled right. For example, consider this model structure:
- Article (template model)
- Title (string)
- Lead (string)
- Body (string)
- Ad
- Headline (string)
- Callout (string)
If I assign an article to the template (Model = article), the first-level string properties are handled properly when they are null. For example, given an article with a null Lead property:
{{ Lead | isNull }}
returns
True
Which is expected.
However, if I try the same thing with an ad that has a null Callout property:
{{ Ad.Callout | isNull }}
the entire expression is just swallowed up. No error… but also no output and the filter never seems to be called.
If Callout has a value (including an empty string), everything works as expected.
Also, I get the same behavior if the object is passed as an Arg. I expected that, since I’m guessing the model behavior is built off the args logic pipeline.
For the moment, I can get around the behavior by guarding everything on the model with null checks. But that’s tedious and error prone.
I hope this makes sense. It took me awhile to track down why my templates weren’t working as expected since the view engine just swallows up the eval.
If I’m doing something wrong, please let me know. But given the inconsistent behavior on very simple tests, I assume this is a deeper issue than user error. And I can’t think of why this might be the expected or as-designed behavior. I’m open to being wrong, however.
I’d love to get feedback on either where I’ve made a mistake, or how I might fix this behavior. Thanks in advance.