Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
controllers.go
type List struct {
	ProductsList []string
	Description  string
	Link         []string
	Success      bool
	Failure      bool
}

func Home(w http.ResponseWriter, r *http.Request) error {
	if r.URL.Path != "/" {
		fmt.Fprintln(w, "404 page not found")
		return nil
	}
	var user List
	for i := 0; i < 35; i++ {
		user.ProductsList = append(user.ProductsList, products.AccessAnotherData(i))
	}
        user = List{
                ProductsList: user.ProductsList,
		Success: true,
		Failure: false,
	}
	if r.Method == "GET" {
		match := database.Get("id1")
		if match {
			RefreshToken(w, r)
			return HomeTmpl.Execute(w, user.Success)
		} else {
			return HomeTmpl.Execute(w, user.Failure)
		}
	} else if r.Method == "POST" {
		...
        // Code for Newsletter
        ...
	}
	return nil
}

Error

can't evaluate field Success in type bool


base.html

{{if .Success}}
    <li>
        <h4><a href="/signout">Sign Out</a></h4>
    </li>
{{end}}
{{if .Failure}}
    <li>
        <h4><a href="/login">Log In</a></h4>
    </li>
{{end}}


What I have tried:

In this code, I am trying to run the conditional statement in the base.html file but I don't know how to make it work. I want if a user signs in then the Sign Out option should be shown. If a user signs out then the Log In option should be shown.
Posted
Updated 11-Dec-21 6:21am
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900