Shape the site
Snippets
A snippet is a file in snippets/ that your writing and templates place
by calling its name.
Write a snippet
In snippets/book.html:
<p class="book"><cite>{{ title }}</cite> by {{ author }}</p>
A snippet is HTML with places for values, written as a
template is. A call names it by its file’s name without
.html, here book, in the letters a to z, digits and _. A snippet
can call another.
Call it from the writing
@book(title='Post 1', author='Name')
@book(...) places the snippet there, on a line of its own or inside a
sentence. Writing has how a call’s values are
written.
Wrap writing in a snippet
In snippets/aside.html:
<aside class="{{ kind }}">{{ body }}</aside>
In the writing:
@aside(kind='tip')
Writing read as *Markdown*, lists and all.
@end
A snippet that shows body wraps writing. Its call stands on a line of
its own and takes the lines below it, up to a line holding only @end.
They are read as Markdown and handed to the snippet as body. Such
calls can be nested.
Call it from a template
In templates/folder.html:
{% for post in page.posts %}
{{ card(post) }}
{% endfor %}
A template calls a snippet inside {{ }}: here snippets/card.html,
once for each post, handed the post. Values are handed as in the
writing, by name or in order:
{{ book(title=page.title, author=page.book.author) }}.
Called inside an attribute, as in href="{{ address_of(tag) }}", a
snippet is written without the line break that ends its file.
A snippet called with no values, as {{ filed() }}, shows what it needs
of page. A new site’s templates call these:
| Snippet | Shows |
|---|---|
called |
A page’s title, or its date and time where it is meant to have none. |
line |
A post as one line of a list. |
entry |
A post in a list, with its picture where asked and its opening. |
short |
A note in a list, its writing whole. |
thumb |
A photograph in a grid, as a link to its page. |
filed |
The page’s series and tags. |
beside |
The links to the pages either side of this one. |
pager |
The way to a list’s pages before and after this one. |
line, entry, short and thumb each write a list item, so each is
called inside <ol> or <ul>.
What a snippet is handed
| Name | What it holds |
|---|---|
| The call’s values | Each under the name the call, or the snippet’s takes line, gives it. |
page |
The page being built, as its template has it. |
site |
The site, as every template has it. |
standalone |
In the writing, true where the call is a line of its own and false inside a sentence. |
body |
For a snippet that wraps writing, that writing, built into HTML. |
A snippet sees only what its call hands it, page and site, and what
it sets itself.
Warning:
In a snippet, page is the page being built, not a page the call hands
it. In snippets/card.html, called as {{ card(post) }}, write
post.title: page.title is the list’s title every time.
Hand it values
| Call | Hands |
|---|---|
book(title='Post 1', author='Name') |
Each value by name. Any snippet takes this. |
card(post) |
One value with no name, to a snippet that takes one name. |
book('Post 1', 'Name') |
Values in order, to the names its takes line gives. |
book('Post 1', 'Name', year=2026) |
Two in order, then the rest by name. |
byline('Name 1', 'Name 2', 'Name 3') |
Any number, as one list, to a name ending ... in its takes line. |
A snippet takes each name it shows. Its first line, the takes line,
names the values a call may give without names, in order. In
snippets/book.html:
{# takes title, author #}
<p class="book"><cite>{{ title }}</cite> by {{ author }}</p>
A takes line names two at most. A name ending ... takes any number
of values, handed as one list:
{# takes names... #}
<p class="byline">{{ names | join(", ") }}</p>
Pieces of the writing
In snippets/markdown/heading.html:
<h{{ level }} id="{{ id }}">{{ body }}</h{{ level }}>
<a href="#{{ id }}" class="heading-anchor">#</a>
A file in snippets/markdown/ builds one piece of the writing your own
way. This one gives every heading a link to itself.
| File | Builds | Is handed |
|---|---|---|
heading.html |
Each heading | level, 1 to 6; id, the heading’s id; classes, the classes written in braces at its end, parted by spaces; body, its words. |
link.html |
Each link | address, as written; title, the link’s title; body, its words; outside. |
image.html |
Each picture written in Markdown | address, as written; alt; title; width and height; photo. |
code.html |
Each code block | code, the code as written; body, the code coloured, as HTML; language; caption. |
inline_code.html |
Code inside a sentence | code, as written. |
footnote.html |
Each place the writing points to a note | number and shown, the note’s number; id, the id of this place; note, the note’s id. |
footnotes.html |
The notes at the foot of the page | notes, each with number, shown, id, back (the id of the place that first points to it) and body; label. |
callout.html |
Each callout | kind, title and body. |
Each file is handed these, and page and site. A value the writing
doesn’t give, such as a link’s title, is empty. A body is HTML Statac
built, shown as it is.
outsidetruewhere the address leads to another site: a host other than the one in the site’surland thosealso_atnames.alt,width,height,photoaltis the description in the brackets, or else the one in the picture’s own file.widthandheightare in pixels where the size is known.photois the picture aspage.photogives it, where the address is a file of the site.language,caption- The first word after the opening fence, and the rest of that line.
Where the first word is a file’s name,
languageis the language the name gives andcaptionis the whole line. number,shownnumberis always written0to9.shownis the same number in the digits of the page’s language:۱on a Persian page.label- What a screen reader says for the link back to the text: “back to the
text” in English, and in any other language the
back_to_the_textline of the site’s file for it, or empty where it has none.
Without a file of your own
| Piece | Statac writes |
|---|---|
| A heading | <h2 id="getting-there">Getting there</h2> |
| A link | <a href="/about/" title="About">about us</a> |
| A picture | A <picture> naming a photograph’s copies, or an <img>: see what goes in the page |
| A code block | <pre class="code"><code class="language-rust">let x = 1;</code></pre>, and with a caption <figure class="code"><figcaption>The caption</figcaption><pre><code class="language-rust">let x = 1;</code></pre></figure> |
| Inline code | <code>let x = 1;</code> |
| A note’s marker | <sup class="footnote"><a href="#note-1" id="back-1">1</a></sup> |
| The notes | <section class="footnotes"><ol><li id="note-1"><p>The note. <a href="#back-1" class="back" aria-label="back to the text">↩</a></p></li></ol></section>, the arrow ↪ where page.direction is rtl |
| A callout | <aside class="callout note"><p>The writing.</p></aside> |
- No call reaches these files:
@heading(...)callssnippets/heading.html. - Where the file for a heading, a code block, a callout or the notes writes only spaces, the piece leaves nothing behind.
- Text a template reads with the
markdownfilter is built bylink.html,code.html,inline_code.htmlandcallout.htmlonly.
Number lines or pick them out
In snippets/markdown/code.html:
<pre class="numbered"{% if caption %} data-lines="{{ caption }}"{% endif %}><code{% if language %} class="language-{{ language }}"{% endif %}>{{ code }}</code></pre>
Statac doesn’t number a block’s lines or pick lines out, but a library
that runs in the reader’s browser can. This file hands it the code as
written, with what follows the language as the lines to pick out: a
block opening rust 2,4 is built as
<pre class="numbered" data-lines="2,4"><code class="language-rust">.
Place the library’s script in the layout’s <head> as any
script: {{ js("lines.js") }}. Where the library
brings its own colours, take {{ css("code.css") }} out of the layout
and add quiet: [code-colours-not-loaded] to statac.yaml.
Why not include?
{% include "card.html" %}
Statac refuses include, import and from. A snippet call is the one
way to place a piece of a page, so a snippet always says what it was
handed. For a frame many templates share, use
extends.
Where next?
- Writing: how a call’s values are written, calls inside HTML, and a call shown as text
- Templates: what a template sees,
extends, and filters such asmarkdown - Pictures: showing a
picture from a snippet with
page.photo - The starter: every snippet a new site has
Something unclear or wrong? Open an issue on GitHub.