Templates

Parts

A part is HTML that templates share, like a header or a card. Write it once in parts/, and pass values in where it needs them.

A part is a piece of HTML that templates share: a header, a footer, the <head>, a card. Put it in parts/ and write {{ part:name }} where it goes:

<!DOCTYPE html>
<html lang="en">
{{ part:head }}
<body>
  {{ part:header }}
  <main>…</main>
  {{ part:footer }}
</body>
</html>

Verso puts the contents of parts/header.html in place of {{ part:header }} before it reads the template, so a part can hold anything a template can: fields, lists, conditions, references, scripts. Change the file once and every template that uses it follows.

Parts that take values

A part can take values, so it works like a component. Give each one a name, then a reference or some quoted text:

{{ each:journal:6 }}
  {{ part:card title=item.title link=item.url date=item.date label="Read the post" }}
{{ /each }}

In the part, {{ part.title }} shows the value, and a reference value can take a format, like {{ part.date:year }}. {{ if:part.date }} checks a reference value:

<article class="col gap:d2">
  <a href="{{ part.link }}" class="font:h5:semibold">{{ part.title }}</a>
  {{ if:part.date }}<time class="font:small">{{ part.date:short }}</time>{{ /if }}
  <span class="font:small">{{ part.label }}</span>
</article>
ValueBecomes
title=item.titleThe reference, as if you had written {{ item.title }} in the part. item., page., parent. and paging. all work
label="Read the post"That text, escaped. Single quotes work too

Rules

  • Parts go in page templates and in blocks. A card used by two blocks, or by a block and a template, is written once. A part can't include another part; that stops with “A part can't use another part.”
  • Give every value the part shows. A missing one stops with “The part "card" shows part.title, but this {{ part:card }} doesn't give it one.”
  • Only references can be checked. {{ if:part.label }} on a quoted value stops with a message; use a reference, or leave the condition out.
  • A field in a part belongs to whatever uses the part: to each page when a template uses it, and to each copy of the block when a block does. For words that are the same everywhere, use a shared field: {{ site.footer:text }} in a footer part is edited once for the whole site. A whole header or footer made of blocks can be a shared block area, {{ site.header:blocks }}.
  • {{ part.title }} only works in a file in parts/.

Errors and classes

A mistake in a part names the part's own file and line, not the template's, and a missing part lists the parts there are. Verso compiles the classes in parts/ even when Elevate's Watch list doesn't name it. A new site's Watch list in elevate/config/elevate.ts already has './parts', so Elevate's own commands see them too; add it if your site is older. The editor reloads when a part changes.