<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>노마드 코인</title>
</head>
<body>
<h1>Home</h1>
</body>
</html>
func home(rw http.ResponseWriter, r *http.Request) {
tmpl := template.ParseFiles("templates/home.html")
}
func home(rw http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("templates/home.html")
}
if err != nil {
log.Fatal(err)
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>노마드 코인</title>
</head>
<body>
<h1>{{.pageTitle}}</h1>
</body>
</html>
type homeData struct {
pageTitle string
}
func home(rw http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("templates/home.html")
if err != nil {
log.Fatal(err)
}
data := homeData{"Home}
tmpl.Execute(rw,data)
}
type homeData struct {
PageTitle string
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>노마드 코인</title>
</head>
<body>
<h1>{{.PageTitle}}</h1>
</body>
</html>
type Block struct {
Data string
Hash string
PrevHash string
}
type homeData struct {
PageTitle string
Blocks []*blockchain.Block
}
func home(rw http.ResponseWriter, r *http.Request) {
tmpl, err := template.ParseFiles("templates/home.html")
if err != nil {
log.Fatal(err)
}
data := homeData{"Home", blockchain.GetBlockchain().AllBlocks()}
tmpl.Execute(rw, data)
}
func home(rw http.ResponseWriter, r *http.Request) {
tmpl := template.Must(template.ParseFiles("templates/home.html"))
data := homeData{"Home", blockchain.GetBlockchain().AllBlocks()}
tmpl.Execute(rw, data)
}
출처 : 노마드코더 노마드코인
[Nomad Coin] Explorer - #5.3 Using Partials (0) | 2022.07.18 |
---|---|
[Nomad Coin] Explorer - #5.2 Rendering Templates (0) | 2022.07.17 |
[Nomad Coin] Explorer - #5.0 Setup (0) | 2022.07.16 |
[Nomad Coin] Blockchain - #4.5 Refactoring part Two (0) | 2022.07.16 |
[Nomad Coin] Blockchain - #4.4 Refactoring part One (0) | 2022.07.16 |
댓글 영역