# HTML Views

### Layouts

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.

{% code title="web/src/layouts/main.html" %}

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

```

{% endcode %}

### Pages

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.

{% code title="web/src/pages/index.html" %}

```html
{{ define "content" }}
<p>
    {{ range .Rockets }}
        {{ partial "rocket" . }}
    {{ end }}
</p>
{{ end }}
```

{% endcode %}

### Partials

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`.

{% code title="web/src/partials/rocket.html" %}

```html
<div>
    This is rocket: {{ .Name }}
</div>
```

{% endcode %}

### Writing HTML Responses

Copper provides `chttp.JSONReaderWriter` that can be used to write HTML responses. `chttp.JSONReaderWriter` 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.

```go
ro.rw.WriteHTML(w, 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.
