Working with layouts
This commit is contained in:
parent
144e700b15
commit
10d4172f3c
@ -8,7 +8,7 @@ import (
|
||||
|
||||
// renderTemplate renders a HTML template file
|
||||
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)
|
||||
if err != nil {
|
||||
fmt.Println("error parsing template:", err)
|
||||
|
@ -1,24 +1,11 @@
|
||||
<!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="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="row">
|
||||
<div class="col">
|
||||
<h1>This is the about page</h1>
|
||||
<p>This is the content</p>
|
||||
</div>
|
||||
{{template "base" .}}
|
||||
{{define "content"}}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>This is the about page</h1>
|
||||
<p>This is the content</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</div>
|
||||
{{end}}
|
||||
|
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,24 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<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="row">
|
||||
<div class="col">
|
||||
<h1>This is the home page</h1>
|
||||
<p>This is the content</p>
|
||||
</div>
|
||||
{{template "base" .}}
|
||||
{{define "content"}}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>This is the home page</h1>
|
||||
<p>This is the content</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</div>
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user