Skip to main content

Module engine

Module engine 

Source
Expand description

Rendering: a theme’s templates compiled into one environment.

An Engine holds a theme’s layouts, pages, partials and assets, with every ancestor’s filling in for the ones the theme lacks, as named templates: layouts/default.htm, pages/home.htm, partials/nav.htm, assets/css/site.css. A page extends a layout with {% extends "layouts/default.htm" %} and fills its blocks; a template includes a partial with {% include "partials/nav.htm" %} or renders one with its own variables through partial("nav.htm", title="Acme"); content("intro.md") places a content block, Markdown rendered to HTML. HTML is escaped everywhere but inside an asset. A printed undefined value is an error; a tested one is not.

check parses a template without rendering it, so a save can refuse a template that would fail. An EngineCache keeps one engine per theme and rebuilds it when the theme or an ancestor changes.

Structs§

Engine
A theme’s templates, compiled and ready to render.
EngineCache
One engine per theme, rebuilt when the theme or an ancestor changes.
RenderError
What went wrong rendering or parsing, with the template and line when known.

Functions§

check
Parses a template’s markup without rendering it. The error carries the line, so an editor can point at it.
render_content
A content block as HTML: Markdown rendered (.md), HTML as it is (.htm, .html), anything else escaped as text.
template_name
The environment name of a template: the kind’s folder and the path.
variant
url|variant("card"): a media URL rewritten to its variant in the preset, replacing one already named. A URL that is not a media URL is returned as it is.