Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Layouts and Partials

A layout is the frame a page renders inside; a partial is a fragment a layout or page includes.

{# layouts/default.htm #}
<!doctype html>
<html>
<head>{{ head }}</head>
<body>
  {% include "partials/nav.htm" %}
  <main>{% block page %}{% endblock %}</main>
</body>
</html>
{# pages/home.htm, with the settings {"url": "/", "layout": "default"} #}
{% block title %}{{ this.page.title }}{% endblock %}
<h1>{{ this.page.title }}</h1>
{{ partial("card.htm", title="Acme", body=page.body) }}
NameGives
layout in a page’s settingsThe layout by name (default for layouts/default.htm); the page then fills its page block, and a block the page defines at its top level fills the layout’s block of that name without rendering in place. A page that writes {% extends %} itself is left as written.
{% block page %} in a layoutWhere the page renders.
{% extends "layouts/<path>" %}, {% block %}A page inside a layout.
{% include "partials/<path>" %}A partial with the current variables.
partial(<path>, name=value, ...)A partial with the named variables, the request’s this and head, and the globals.

Name a template

KindName
Kind::Layoutlayouts/default.htm
Kind::Pagepages/home.htm
Kind::Partialpartials/nav.htm
Kind::Assetassets/css/site.css

A theme’s own template is used, else the nearest ancestor’s (see Child Themes).

Save a layout or partial from Rust

store::save_template(&db, site.id, Kind::Layout, "default.htm", None, LAYOUT, None).await?;
store::save_template(&db, site.id, Kind::Partial, "nav.htm", None, NAV, None).await?;

The path rules and the other calls are under Themes.

Give a partial a role

Partial atRole
partials/<alias>/default.htmThe markup of the component attached under <alias> (see Components).
partials/<code>/default.htmThe markup of the component offered as the snippet <code> (see Snippets).
A partial with snippet in its settingsAn insertable block in the rich and markdown editors (see Snippets).