# Template

The template is the HTML shell around each page. Pass your own with
`--template`, `"template"` in `charon.json`, or the Vite plugin's `template`.

Each `{{name}}` is filled once; text in the page is never read as a
placeholder. A placeholder charon does not know fails the build, so a typo
never ships.

## Placeholders

| Placeholder          | Value                                                       |
| -------------------- | ----------------------------------------------------------- |
| `{{lang}}`           | `lang`, such as `en`                                        |
| `{{title}}`          | the page title, escaped                                     |
| `{{description}}`    | the page description, escaped                               |
| `{{name}}`           | the site name, escaped                                      |
| `{{url}}`            | `siteUrl` plus the page route                               |
| `{{home}}`           | the route of the root page                                  |
| `{{base}}`           | the base, such as `/docs`, or empty                         |
| `{{markdown}}`       | the route of the Markdown copy                              |
| `{{markdownLink}}`   | a "View as Markdown" button that opens the copy             |
| `{{image}}`          | the URL of the page's social card; empty without `og`       |
| `{{updated}}`        | a `p.charon-docs-updated` with the last commit date         |
| `{{nav}}`            | a `details` menu for phones and a sticky `nav`              |
| `{{content}}`        | the rendered page; wrap it in `.charon`                     |
| `{{contentsInline}}` | "On this page" for narrow screens, to put above the content |
| `{{contents}}`       | the "On this page" column                                   |
| `{{footer}}`         | the previous and next links                                 |
| `{{meta}}`           | Open Graph and Twitter tags, with the card if `og` is set   |
| `{{head}}`           | extra head tags, such as the KaTeX stylesheet               |

## The default

This is charon's own template, a fine place to start:

```html
<!doctype html>
<html lang="{{lang}}">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>{{title}} — {{name}}</title>
    <meta name="description" content="{{description}}" />
    <link rel="canonical" href="{{url}}" />
    <link rel="alternate" type="text/markdown" href="{{markdown}}" />
    <link rel="stylesheet" href="{{base}}/_charon/docs.css" />
    {{meta}} {{head}}
    <script type="module" src="{{base}}/_charon/docs.js"></script>
  </head>
  <body>
    <main class="charon-docs-layout">
      {{nav}}
      <div class="charon-docs-main">
        <article class="charon">
          <div class="charon-docs-title">
            <h1>{{title}}</h1>
            {{markdownLink}}
          </div>
          {{contentsInline}} {{content}}
        </article>
        {{updated}} {{footer}}
      </div>
      {{contents}}
    </main>
  </body>
</html>
```

The package ships it as `docs-template.html`, with its layout in
`docs-layout.css`.

## Layout

`{{nav}}`, the main column and `{{contents}}` are three siblings, so a
three-column grid lays them out. `docs-layout.css` does that, and stacks them
on narrow screens.

Keep `{{head}}` in the `head`: pages with math put KaTeX's stylesheet there.
With the CLI, keep the `_charon/docs.css` and `_charon/docs.js` tags too, or
add your own.

## Turn off keys

The CLI's script reads two switches from the `html` element:
`<html lang="{{lang}}" data-charon-docs-arrow-keys="off" data-charon-docs-search-key="off">`.

`data-charon-docs-arrow-keys="off"` stops <kbd>←</kbd> and <kbd>→</kbd> from turning
pages; `data-charon-docs-search-key="off"` frees <kbd>Ctrl</kbd> <kbd>K</kbd>.
