Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If not true (!true)

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 }} 
like image 259
Ari Seyhun Avatar asked Dec 22 '16 14:12

Ari Seyhun


People also ask

Is true && false true?

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).

Is an if statement true or false?

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.

Is true if both operands are true?

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.


1 Answers

Use the function not:

{{ if not .loggedIn }} <h1>Not logged in</h1> {{ end }} 
like image 148
hlscalon Avatar answered Sep 30 '22 06:09

hlscalon