HTML

Context

Templates can access a variety of “contexts” and “variables” to build a document:

doc contains:

site contains:

Nested entries expose these fields:

Layouts

HTML layouts are MiniJinja templates; see Templating for the syntax. For a single HTML notebook, use layouts/document.html. For websites, the default entry is layouts/site.html.

Here is a minimal layouts/document.html:

{{ doc.head }}
  <meta charset="UTF-8">
  <title>{{ doc.title }}</title>
  {% for file in css %}
  <style>
{{ file.content }}
  </style>
  {% endfor %}
{{ doc.body_open }}
  <header class="document-header">
    <a href="index.html">Home</a>
    <button type="button" data-calepin-theme-toggle>Theme</button>
  </header>
  <main class="container">
    {{ doc.body }}
  </main>
  {% for file in js %}
  <script>
{{ file.content }}
  </script>
  {% endfor %}
{{ doc.body_close }}

Keep doc.head, doc.body_open, and doc.body_close unless you are intentionally replacing the entire HTML shell.

Partials

Instead of maintainng large monolithic templates, it is useful to split templates into different “partials”, that is, templates that handle a specific part of a web page. This allows re-useability and makes the codebase more maintainable. These templates are hosted under partials/, and we include them in a layout with the {% include %} tag.

{% include "partials/header.html" %}

Partials receive the same template context as the file that includes them. Shared partials from the bundled base layer are included by both built-in themes; a theme-local partial with the same path overrides the shared one. To customize one component, copy that partial into your local theme and edit it there.

The bundled themes currently provide these partials. This list is descriptive; the theme source code on GitHub is canonical.

Shared partials:

calepin theme partials:

academic theme partials:

Page-specific layouts

Sometimes, we would like a specific page of a website to use a different layout than the default. For instance, the landing page is often very different than the other pages of a site.

You can switch layouts per page with <website-metadata>:

#metadata((
  title: "Landing page",
  layout: "layouts/site-landing.html",
)) <website-metadata>

The layout value must be a relative .html path inside the active theme. Calepin does not add layouts/ or .html for you and does not fall back to layouts/site.html if the file is missing.