HTML Views


The layout generally contains the HTML skeleton such as the <head>, <body>, and other elements that your page may need. It leaves stubs for the page by defining template areas. These areas are defined by the page and are filled in dynamically.

By default, Copper generates the web/src/layouts/main.html. You can create as many layouts here as your app needs.

<!DOCTYPE html>
<html lang="en">
    <title>Command Center</title>
    {{ template "content" }}


A page represents the document that is rendered for a specific URL path. It is contained inside of a layout. It must define each template required by the layout.

{{ define "content" }}
    {{ range .Rockets }}
        {{ partial "rocket" . }}
    {{ end }}
{{ end }}


Finally, partials provide a way to move HTML snippets into their own components. These are defined in the web/src/partials directory. A partial named "rocket" must be defined in rocket.html.

    This is rocket: {{ .Name }}

Writing HTML Responses

Copper provides chttp.ReaderWriter that can be used to write HTML responses. chttp.ReaderWriter is available by default on Routers generated by the Copper CLI.

Use the WriteHTML method to take advatange of the layouts, pages, and partials defined in the web/ directory., r, chttp.WriteHTMLParams{
	PageTemplate:   "index.html",
	LayoutTemplate: "main.html",
	Data: map[string][]posts.Post{
		"Rockets": allRockets,

In the example above, the main.html layout is used to render the index.html page. We also pass in data that can be accessed within the Go templates.

Last updated