Templates

Conditions

A condition shows one part of a template when something is filled in, and another when it isn’t, so a page without a cover image doesn’t show an empty frame.

A condition shows everything between {{ if:… }} and {{ /if }} only when the thing it checks has something in it. Whatever sits after {{ else }} shows when it doesn't:

{{ if:cover }}
<figure class="mg-b:d8">
  <img src="{{ cover:image }}" class="w:full h:auto">
  <figcaption class="font:small text:ink-3">{{ caption:text }}</figcaption>
</figure>
{{ else }}
<div class="h:d12 bg-color:paper-2"></div>
{{ /if }}

Three ways to ask

WriteShows its contents when
{{ if:cover }}cover has something in it
{{ if:!cover }}cover is empty
{{ if:kind=essay }}kind is essay
{{ if:kind!=essay }}kind is anything but essay, including empty

Comparisons ignore capitals and spaces at the ends, so kind=essay matches “Essay”. Put a value with spaces in quotes: {{ if:kind="case study" }}. Use either ! or a comparison, not both.

What counts as filled

FieldFilled when
TextIt has anything other than spaces
Rich textIt has visible text, an image or a video. An empty paragraph doesn't count
ImageA file is chosen
ColourA colour is chosen
Page settingThe setting has a value. title falls back to the page's label, so it is always filled

What it can check

WriteChecks
{{ if:cover }}A field in this template. The field must exist, or Verso stops and says so
{{ if:item.cover }}A field or setting of each page in a list. Only inside {{ each }}
{{ if:page.tag }}A setting of the page being rendered: description, date, tags, tag and the rest
{{ if:parent.lede }}A field or setting of the page one level up
{{ if:site.notice }}A shared field
{{ if:paging.next }}Whether a split list has a next page. Also paging.previous. See Pages of a list

A useful pattern is a field kept in Page settings that decides whether part of the page exists at all. Here the link appears only once someone has given it an address:

{{ if:video-url }}
<a href="{{ video-url:text }}" class="row:y-center gap:d2 font:small:semibold">Watch the talk</a>
{{ /if }}

In lists

Inside a list, item. conditions run once per page, so each card can decide for itself:

{{ each:work:newest }}
<a href="{{ item.url }}" class="col gap:d3">
  {{ if:item.cover }}<img src="{{ item.cover }}" class="w:full aspect:landscape">{{ /if }}
  <span class="font:h5:semibold">{{ item.title }}</span>
  {{ if:item.kind=case-study }}<span class="font:small">Case study</span>{{ /if }}
</a>
{{ /each }}

A list has an {{ else }} of its own, for when it is empty. See Lists of pages.

In the editor

When a condition checks one of this page's own fields, the editor shows the part that holds this page's fields, even when the field is empty. Otherwise an empty field would hide the very place you would click to fill it. With {{ if:!cover }}…{{ else }}<img src="{{ cover:image }}">{{ /if }}, the editor shows the image part, so the cover can be chosen. If both parts or neither hold fields, the condition is checked as usual. The built page always follows the condition.

Conditions on item., page., parent., site. and paging. behave the same in the editor as on the live site.

Rules

  • Conditions nest, inside each other and inside lists.
  • Each {{ if }} takes one {{ else }} at most. A second stops with “There's already an {{ else }} for …”.
  • They go between elements, never inside a tag or a <title>. To change an attribute, put two versions of the element in the two parts of a condition, or make the attribute a field.
  • Every {{ if }} needs its {{ /if }}. A missing or mismatched one stops with the line of the one still open.
  • Keep each condition around whole elements. Verso doesn't check that the HTML inside a condition is balanced, and an opening tag shown without its closing tag breaks the page.