layout.php

A layout is a UI shell shared across multiple routes. It allows you to define headers, sidebars, and footers once, automatically applying them to all pages within a directory.

The Root Layout

The top-most layout is located in app/layout.php. This is the entry point for your HTML structure.

app/layout.php
<?php use PP\MainLayout; ?>
<!DOCTYPE html>
<html lang="en">
    <body>
        <!-- Page content is injected here -->
        <?= MainLayout::$children ?>
    </body>
</html>

Nested Layouts (Dashboard Example)

To apply a specific look to a section of your app (like a Dashboard), create a layout.php inside that folder. It will wrap any page inside that directory.

Use <?= MainLayout::$children ?> to specify where the inner page content should render.

Visual Output

The code on the right produces a standard dashboard grid.

Sidebar
Top Menu
Content (Children)
app/dashboard/layout.php
<?php

use PP\MainLayout;

?>

<div class="grid grid-cols-5 grid-rows-5 gap-4 h-screen">
    <div class="row-span-5 bg-gray-100">Sidebar</div>
    <div class="col-span-4 bg-white border-b">Top Menu</div>
    
    <!-- Page Content Injection Point -->
    <div class="col-span-4 row-span-4 p-4">
        <?= MainLayout::$children ?>
    </div>
</div>

Route Groups & Multiple Root Layouts

Advanced

Sometimes you need completely different HTML structures for different parts of your app (e.g., a Marketing Site vs. an Admin Panel). You can use Route Groups to achieve this without affecting the URL structure.

The Concept

A folder named with parentheses, like (group), is ignored by the URL router. This lets you create new layout contexts at the root level.

Use Case

You want your Login Page to have no sidebar, but your Dashboard to have complex navigation. Grouping them lets them share the same URL depth but use different layout.php files.

// Directory Structure
app/
(marketing)/
layout.php // Marketing Theme
index.php -> URL: /
about/index.php -> URL: /about
(admin)/
layout.php // Admin Theme + Sidebar
dashboard/index.php -> URL: /dashboard