In golang's template/html package, I can use {{ if .loggedIn }}
to check if logged in is true.
How do I check if .loggedIn is false without using ne or eq?
For example, I am looking for something like
{{ if !.loggedIn }} <h1>Not logged in</h1> {{ end }}
If applied to boolean values, the && operator only returns true when both of its operands are true (and false in all other cases), while the || operator only returns false when both of its operands are false (and true in all other cases).
The test can be any expression that evaluates to a boolean value – true or false – value (boolean expressions are detailed below). The if-statement evaluates the test and then runs the body code only if the test is true. If the test is false, the body is skipped.
If both operands have values of true , the result has the value true . Otherwise, the result has the value false . Both operands are implicitly converted to bool and the result type is bool . Unlike the & (bitwise AND) operator, the && operator guarantees left-to-right evaluation of the operands.
Use the function not
:
{{ if not .loggedIn }} <h1>Not logged in</h1> {{ end }}
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