If not true (!true)

If StatementGoGo Templates

If Statement Problem Overview


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 Statement Solutions


Solution 1 - If Statement

Use the function not:

{{ if not .loggedIn }}
<h1>Not logged in</h1>
{{ end }}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAri SeyhunView Question on Stackoverflow
Solution 1 - If StatementhlscalonView Answer on Stackoverflow