Documentation · Chapter 05

Reuse HTML
without hiding it.

A partial is a small view file included by another view. It remains ordinary PHP and HTML.

We improve reading-list without changing its HTTP logic or temporary session storage.

The engine looks in one exact folder

The partial() method searches only under src/views/partials. The supplied name is relative to that folder.

phpaml — zsh
<?php $view->partial('header.php') ?>
<?php $view->partial('footer.php') ?>

These calls load src/views/partials/header.php and src/views/partials/footer.php. A missing file causes a clear error instead of being silently ignored.

Create the shared head

src/views/partials/head.php

phpaml — zsh
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="<?= $view->escape($description ?? '') ?>">
<title><?= $view->escape($title ?? 'Reading List') ?></title>
<link rel="stylesheet" href="/css/app.css">

The ?? operators provide a fallback when title or description are not supplied.

Pass values to the partial

phpaml — zsh
<!DOCTYPE html>
<html lang="en">
<head>
    <?php $view->partial('head.php', [
        'title' => 'My books',
        'description' => 'Your personal library.',
    ]) ?>
</head>
<body>
    <?php $view->partial('header.php') ?>
    <main><!-- contenu propre à la page --></main>
    <?php $view->partial('footer.php') ?>
</body>
</html>

The second argument array is extracted only for that partial. The head receives the metadata it needs without depending on global variables.

Partial or complete page?

Shared navigationpartials/header.php
Title + author fieldspartials/book-form.php
Complete book listbooks/index.php
Add form pagebooks/create.php
The classic engine does not impose a layout system

Composition is explicit through partial(). This transparency makes it clear which file produces each part of the document.