Working with layouts
This commit is contained in:
parent
144e700b15
commit
10d4172f3c
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// renderTemplate renders a HTML template file
|
// renderTemplate renders a HTML template file
|
||||||
func RenderTemplate(w http.ResponseWriter, tmpl string) {
|
func RenderTemplate(w http.ResponseWriter, tmpl string) {
|
||||||
parsedTemplate, _ := template.ParseFiles("./templates/" + tmpl)
|
parsedTemplate, _ := template.ParseFiles("./templates/"+tmpl, "./templates/base.layout.tmpl")
|
||||||
err := parsedTemplate.Execute(w, nil)
|
err := parsedTemplate.Execute(w, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("error parsing template:", err)
|
fmt.Println("error parsing template:", err)
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
{{template "base" .}}
|
||||||
<html lang="en">
|
{{define "content"}}
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>About page</title>
|
|
||||||
<link href="css/style.css" rel="stylesheet">
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
||||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@ -19,6 +8,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
{{end}}
|
||||||
|
|
||||||
</html>
|
|
||||||
|
24
templates/base.layout.tmpl
Normal file
24
templates/base.layout.tmpl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{{define "base"}}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>About page</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||||
|
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||||
|
{{block "css" .}}
|
||||||
|
{{end}}
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{{block "content" .}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{block "js" .}}
|
||||||
|
{{end}}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
|
{{end}}
|
@ -1,16 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
{{template "base" .}}
|
||||||
<html lang="en">
|
{{define "content"}}
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>Home page</title>
|
|
||||||
<link href="css/style.css" rel="stylesheet">
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
|
|
||||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
@ -19,6 +8,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
{{end}}
|
||||||
|
|
||||||
</html>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user