Views
A page's view selects the template that renders it.
On this page
Resolution
A page's template comes from its view (default default). A view is your site's own template. The folder form is checked before the flat file:
site/views/{view}/index.latte ← checked first
site/views/{view}.latte
If nothing resolves, a NotFoundException is thrown.
Naming a view
When a page can have children of more than one view, the new-page form offers them in a View picker. A view names itself there with a label in its _index.json, and falls back to its ref:
// site/views/post/_index.json
{
"label": "Blog post"
}
Template variables
Every view receives $page. $app is not available.
Layouts
Share an outer shell with {layout} and {block}:
{* site/views/post/index.latte *}
{layout 'layout.latte'}
{block main}
<article>
<h1>{$page->title}</h1>
<div class="prose">{$page->body|render}</div>
</article>
{/block}
The layout fills the body block of the HTML shell, site/views/index.latte, and declares the main block for each view:
{* site/views/layout.latte *}
{layout 'index.latte'}
{block body}
<main>
{include 'header.latte'}
{block main}{/block}
{include 'footer.latte'}
</main>
{/block}
For syntax, filters and functions, see Latte Templates.
$page is the response's page
In every template, $page is the page rendering the whole response. A template reached through {include} from more than one place sees the including page as $page, not a page of its own. One that builds a URL against itself, such as an hx-get or a form action, should name its page: p('widgets')->url().
When you need more
A view can also have its own routes, data and page logic. See Controllers.