Titles in an Array in PHP
Let's now create a file where we will store page URLs and their corresponding titles in the form of an array:
<?php
return [
'/page1' => 'page 1 title',
'/dir/page2' => 'page 2 title',
'/dir/sub/page3' => 'page 3 title',
];
?>
On the page index.php, we will get the array
of titles into a variable:
<?php
$titles = require 'titles.php';
?>
Let's get the title of the requested page:
<?php
$title = $titles[$url];
?>
Let's replace the corresponding command in the template file with our title:
<?php
$layout = str_replace('{{ title }}', $title, $layout);
?>
Implement titles stored in an array in your engine.