Theme contract
This page lists what a SightPress theme can rely on and must provide. It is generated from the sightpress/theme-interface
package. To build a theme step by step, follow the Create a theme tutorial.
A theme is presentation only: design tokens, Twig templates, assets and translations. Anything with behaviour is a
module.
theme.json
Key
Required
What it is
name
Yes
The theme id; must equal the id in the theme's manifest.
label
Yes
Name shown to people.
version
Yes
The theme's version (Semantic Versioning); must equal the version in the theme's manifest.
colors
Yes
The colours for light and dark mode, and optionally for more contrast.
typography
Yes
Fonts and text sizes.
spacing
No
The spacing scale.
radius
No
Corner radii.
focus
No
The focus outline.
contrast
No
Colour pairs core checks in every colour mode: text needs 4.5:1, interface colours 3:1 (WCAG 2.2 AA).
chart
No
Which of the theme's colours the data series of a chart use, in order; without it they use chart-1 to chart-4. Core checks each series colour for 3:1 and chart-text for 4.5:1 on background and surface in every colour mode.
Token groups
Each group becomes CSS custom properties with this prefix.
Group
Prefix
typography
--font-
spacing
--space-
radius
--radius-
focus
--focus-
Charts use the colours chart-1, chart-2, chart-3, chart-4, chart-grid, chart-text.
Layouts
Id
Name
Required
What it is
default
Default
Yes
One column at a comfortable reading width.
home
Home
Yes
An introduction band, then content at full page width.
search
Search results
Yes
The search form and the list of results.
landing
Landing
No
A wide introduction band, then content in full-width sections.
sidebar
Sidebar
No
Content with a side column for related links and notes.
full-width
Full width
No
Content across the whole page width, without a reading column.
Required templates
master.html.twig
Page shell every page extends. Sets lang and dir on from the page's language, includes the core
partial, makes "Skip to main content" the first thing to tab to, and has the landmarks , for each menu and the language switcher, the site's form (partials/search-form.html.twig, when search_action is set), and . Shows messages at the top of through partials/messages.html.twig. The is document_title when set, else the title block and the site name, with "Error: " in front when the form has errors. Main menu items may have children, up to three levels, shown as nested lists that work without JavaScript.
Twig blocks: title, head, brand, breadcrumbs, main, footer, scripts.
Variable
Type
Required
What it is
site_name
string
No
The site's name.
locale
string
No
BCP 47 tag of the page's language; else current_locale().
document_title
string
No
The whole , when core sets it (SEO title, search results).
home_url
string
No
The home page in the page's language; else "/".
branding_logo
array{url: string, alt: string, width: int, height: int}
No
The uploaded logo, shown instead of the site's name in the header link.
main_menu
list<array{label: string, url: string, current?: bool, children?: list<array<string, mixed>>}>
No
Items of the main menu; current marks the page shown.
footer_menu
list<array{label: string, url: string, current?: bool, children?: list<array<string, mixed>>}>
No
Items of the footer menu.
breadcrumbs
list<array{label: ?string, url: string}>
No
Where the page is on the site, the last item the page itself; a null label is the home page.
languages
list<array{code: string, name: string, url: string, current: bool}>
No
The page in each published language, each named in its own language, for the language switcher; empty when there is only one.
search_action
string
No
Where the header's search form searches, while site search is on.
messages
list<string>
No
Messages to show once, such as "Page saved".
form
array{errors: array<string, list<string>>}
No
The form on the page, if any.
layouts/default.html.twig
One column at a comfortable reading width: the title, the lead, then the content.
Twig blocks: content.
Variable
Type
Required
What it is
title
string
Yes
The page title, shown as the only .
lead
string
No
A short summary shown under the title.
updated_at
DateTimeInterface
No
When the page last changed (UTC), shown as "Last updated" with user_date in a .
layouts/home.html.twig
An introduction band with the title and lead, then the content at full page width.
Twig blocks: hero, content.
Variable
Type
Required
What it is
title
string
Yes
The page title, shown as the only .
lead
string
No
A short summary shown under the title.
updated_at
DateTimeInterface
No
When the page last changed (UTC), shown as "Last updated" with user_date in a .
layouts/search.html.twig
Site search: the title as the only
(what was searched for and how many results there are; core also puts it in , so screen readers announce both when the page loads, without a live region), the search form, then the results as a numbered list (), each with its title as a link in an , its trail and its extract with the matched words in . When nothing was found, nothing was searched for yet, or there were too many searches, the page says so in words, with tips.
Twig blocks: content.
Variable
Type
Required
What it is
title
string
Yes
The heading, for example "3 results for “river”".
query
string
Yes
What was searched for; empty before a search.
action
string
Yes
Where the search form searches.
state
'results'\|'none'\|'empty'\|'busy'
Yes
results; none found; empty (nothing searched for yet); busy (too many searches, see retry_minutes).
total
int
Yes
How many results there are in all.
first
int
Yes
The number of the first result on this page.
matched_all
bool
Yes
False when no page has every word, so results have some of them.
results
list<array{title: string, url: string, excerpt: string, locale: string, trail: string, extract: list<array{text: string, mark: bool}>}>
Yes
The results on this page, best first; excerpt is plain text, extract the same text in pieces, mark true for matched words; trail is where the page is on the site.
pagination
?array{current: int, pages: int, previous: ?string, next: ?string, pattern: string}
Yes
Links to the other pages of results, or null; pattern is a sprintf() URL with %d for the page.
language_name
string
Yes
The name of the language searched, in that language.
retry_minutes
?int
Yes
Minutes to wait before searching again, when busy.
partials/messages.html.twig
Messages in a polite live region (role="status") that is always there, even when empty, so screen readers know it. Core's own views include it too.
Variable
Type
Required
What it is
messages
list<string>
Yes
The messages; may be empty.
A search form in a landmark named by its visible label (aria-labelledby), with a search input named "q" and a visible "Search" button, sent with GET. Works the same without JavaScript. The shell and the search layout both include it, so its ids start with id.
Variable
Type
Required
What it is
action
string
Yes
URL the form is sent to with GET.
query
string
No
What was searched for, to fill the input.
id
string
No
Start of the form's ids, "search" by default, so a page can have two forms.
label
string
No
The visible label, "Search this site" by default.
Twig functions and filters
Name
Kind
Use
What it does
asset
function
asset(string path): string
URL of a file in the theme's assets/ folder, with its version in the name so it can be cached. The generated design tokens are at asset('tokens.css').
t
function
t(string message, array parameters = {}, string domain = 'messages'): string
The message translated to the page's language; write messages in British English.
can
function
can(string permission): bool
Whether the person viewing the page has the permission on this site.
csp_nonce
function
csp_nonce(): string
The Content Security Policy nonce for this response, for the rare inline
Back to top