Layouts

Set the page layout

In the product example, ProductPage extends AppPage. Atom Starter sets the shared layout on AppPage, so every page that extends it inherits the same layout.

app/Pages/AppPage.php (excerpt)
<?php

namespace App\Pages;

use App\Components\SiteLayout;
use Atom\Page\Page;

abstract class AppPage extends Page
{
    public ?string $layout = SiteLayout::class;
}

ProductPage.atom.html contains the product screen. The shared layout provides the surrounding HTML document, including the header, footer, and client scripts.

ProductPage.atom.html (excerpt)
<h1>{{ $this->product->name }}</h1>
<p>{{ $this->availabilityLabel() }}</p>

Render the product inside the layout

When a shopper opens /products/42, Atom calls ProductPage::get("42") and renders the product template with that page instance. It then passes the page instance and its rendered content to SiteLayout. The layout can read page metadata such as the title, and its template inserts the rendered content inside <main>.

app/Components/SiteLayout.atom.html (excerpt)
<main id="main" class="site-main" atom:update-root>
    {{ $context->fragmentHtml($this->content) }}
</main>

The browser receives one HTML document with the product heading and stock label inside <main>. The same layout can wrap the catalogue, and Enhanced navigation shows how Atom updates that main area when the shopper moves between the two pages.