Layouts
A layout is a .kreft file in layouts/ with a <slot> where the page goes. The bar and the menu around this page are layouts/main.kreft.
Which layout a page gets
| Where | What you write | Here |
|---|---|---|
| Every page | Kreftjs.router({ layout: 'main', routes }) | this page, Basics, Forms… |
| One route and its children | { path: '/docs', …, layout: 'plain' } | Docs |
| Inside the page file | layout plain | Start |
| No layout | layout: false or layout none |
The route wins over the page file, and the page file over the router. Going from page to page with the same layout keeps it: the menu doesn't flicker and keeps its state.
Sections: @section and @yield
The Save button at the top right is part of this page, shown in the bar. Press it: the count is this page's state.
<!-- layouts/main.kreft, or a component in it --> <kreft-yield name="actions">shown when the page has none</kreft-yield> <!-- pages/Layouts.kreft --> <kreft-section name="actions"> <button class="primary sm" @click="saved++">Save</button> </kreft-section>
Leave the page and the button goes with it.
A layout file
<!-- layouts/main.kreft -->
state menuOpen = false
<view>
<site-header></site-header>
<nav>…</nav>
<main>
<slot></slot> <!-- the page -->
</main>
</view>