Building a site
Templates
Page files are Tempest views. They use Tempest's syntax: {{ }} prints an escaped value, {!! !!} prints raw HTML, and attributes that start with a colon, such as :foreach and :if, control the flow.
Every template has these variables:
$page: the current page, a read-onlyLapis\Content\Page(title,description,path,type,status,url(),slug(),exists(),isPublished(),block('name'),text('name', 160),date(),meta('key'))$site: the global settings ({{ $site->site_name }},$site->get('menu', []))$cms: the helpers, such aspages(under:, type:, order:, limit:, offset:),paginate($items, perPage:, page:, param:, maxLinks:),paginatePages(under:, type:, order:, perPage:, page:, param:, maxLinks:),pageUrl($page, param:, preserve:),find($path),data(),asset(),setting(),title(),locale(),menu(),active(),query(),htmx(),htmxTarget(),isEditor(),isEditing(),global()andimageVariant(). Theorder:ofpages()andpaginatePages()takes'newest'(the default),'oldest','title','sort','path'or'updated'.$params: the route parameters ($params['slug'])
The setup block
The <?php … ?> block at the top of a template is its setup block. The variables you define there are available in the whole template, in the slot of <x-layout> too:
<?php // pages/index.php $posts = $cms->pages(under: 'blog', type: 'post', limit: 3); ?> <x-layout> <x-post-card :foreach="$posts as $post" /> </x-layout>
The setup block is also where page functions live: a loader for the template's data, or a function that answers a POST.
Built-in components
Lapis ships these components:
<x-block>: an editable block<x-repeat>: a repeatable list<x-form>: a form fromforms/<x-pagination :pages="$items" />: previous, page number and next links for aPaginatedDataresult (renders nothing when everything fits on one page, keeps existing query parameters unlesspreserve="false", and acceptsparam,previous,next,label,classandhx-*attributes)<x-importmap />or<x-importmap entrypoint="admin" />: the import map, CSS and modulepreload links (Assets)<x-seo />: title, description, canonical and Open Graph tags (SEO).title,descriptionandimagecan be overridden.
A component with the same name in the site's components/ folder overrides the package's own.
Your own components
Your components are x-*.view.php files in components/, and Tempest discovers them. Inside a component, read its attributes from the $attributes array:
<?php // components/x-card.view.php $cardTitle = $attributes['title'] ?? null; ?> <article class="card"> <h3 :if="$cardTitle">{{ $cardTitle }}</h3> <x-slot /> </article>
Menu from pages
In the Page panel, "Show in menu" and a menu label put a page in the menu. The order is set in the Pages panel, under "Menu order". In a template, $cms->menu() returns the items:
<nav> <a :foreach="$cms->menu() as $item" :href="$item['url']" :aria-current="$item['active'] ? 'page' : null">{{ $item['label'] }}</a> </nav>
While no page is marked, $cms->menu() returns the menu setting. To copy a page, use Duplicate in the Page panel: it makes a hidden copy with the same content.
Translations
Every text Lapis shows to visitors and editors goes through Tempest's translator (its localization): the validation messages, the form texts, the login pages, the e-mails and the whole editor. A text has a key (lapis.editor.publish), and its message is in a <name>.<locale>.yml file (Lapis's and the plugins' lang/messages.<locale>.yml, the site's app/localization.<locale>.yml), in the MessageFormat 2 syntax. Lapis ships English and Hungarian. The locale of lapis.config.php picks the language, and a text with no message in it is shown in English.
Tempest finds every such file by itself. They are read in this order, and a later one wins:
- Lapis's own (
lang/messages.en.yml,lang/messages.hu.ymlin the package), - the plugins' (in their
lang/), - the site's, in
app/: for a language Lapis does not ship, to change single texts, or for the site's own.
A site only needs its own file for what is missing, or for what should read differently:
# app/localization.de.yml lapis: common: required_field: "Pflichtfeld." editor: publish: "Veröffentlichen" count_drafts_published: | .input {$count :number} .match $count one {{{$count} Entwurf veröffentlicht.}} * {{{$count} Entwürfe veröffentlicht.}} site: welcome: "Willkommen, {$name}!"
The keys and the English texts are in the package's lang/messages.en.yml. In PHP, translate with Tempest's function, translate('site.welcome', name: 'Ada') (use function Tempest\Intl\translate), in a template the same, with that use function at its top. Inside a component's slot (such as <x-layout> or <x-block>), call it with its namespace ({{ \Tempest\Intl\translate('site.welcome', name: 'Ada') }}), because Tempest does not carry use function imports into slots. Editor modules use lapis.t('site.welcome', { name: 'Ada' }). A label given to a field, a column or a panel is translated too, and one that is no key (a site's own 'Phone') is shown as it is.
The locale also sets <html lang>, og:locale and the date formats of the editor.