79386437

Date: 2025-01-25 09:08:06
Score: 0.5
Natty:
Report link

have you looked into standard library template documentation?

From the documentation it seems possible to create a layout:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>{{.Title}}</title>
    </head>
    <body>
        {{ template "content" . }}
    </body>
</html>

Example (home.html):

{{ define "content" }}
    <h2>Welcome to the Home Page</h2>
    <p>This is the home page content.</p>
{{ end }}
tmpl := template.Must(template.ParseFiles("layout.html", "home.html"))

// Data to be passed to the template
data := struct {
  Title string
}{
  Title: "Home Page",
}

This could be returned by your http response.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: mopmop