Incorrect username or password

Compare strings in patterns

I have the following template:

{{if . eq "login failed"}} <span class="text-error">Incorrect username or password</span> {{else if . eq "login success"}} <span class="text-success">You have successfully logged in!</span> {{end}} 

I pass the string when the template is executed.

However, I get the following error:

 executing "login.html" at <.>: can't give argument to non-function . 

How to compare lines in a template?

+17
source share
1 answer

eq is a function , not an operator. It is called in the form: eq <x> <y> (not <x> eq <y> ).

You can fix your pattern by moving the operands from the eq sides to:

 {{if eq . "login failed"}} <span class="text-error">Incorrect username or password</span> {{else if eq . "login success"}} <span class="text-success">You have successfully logged in!</span> {{end}} 
+36
source

All Articles