The engine looks in one exact folder
The partial() method searches only under src/views/partials. The supplied name is relative to that folder.
<?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
<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
<!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?
Composition is explicit through partial(). This transparency makes it clear which file produces each part of the document.