ssn771
ssn771

Reputation: 1270

How is if statement evaluated in freemarker?

I am trying to understand how freemarker evaluates an if statement with multiple conditions for example:

<#if person?? && person.phone?has_content && person.phone != "11">
    do something
</#if>

If person?? returns false will freemarker still evaluate the rest of the statement or will it just return false for the whole statement? I'm trying to figure out if person.phone is null will this if statement throw an error when it tries to evaluate the last condition in the if statement? I was trying make it as clean as possible instead of having to nest a bunch of if statements.

Thanks!

Upvotes: 4

Views: 8373

Answers (1)

knoight
knoight

Reputation: 479

In Java the logical operators && and || short-circuit, meaning they do not evaluate anything after the operator if they do not need to.

In the example you've given if person evaluates to false then the rest of the condition will not be evaluated.

This answer provides a good example

Also, the last post in this forum thread speaks specifically to freemarker supporting short-circuiting logical operators

Upvotes: 3

Related Questions