Метод 1. Использование HTML-тега заголовка.
Один из самых простых и распространенных методов — использование HTML-тега <title>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $pageTitle; ?></title>
</head>
<body>
<!-- Your page content goes here -->
</body>
</html>
. 1
<?php
function setPageTitle($title) {
echo "<title>$title</title>";
}
?>
<!DOCTYPE html>
<html>
<head>
<?php setPageTitle("My Page Title"); ?>
</head>
<body>
<!-- Your page content goes here -->
</body>
</html>
config.php:
<?php
$config = [
'pageTitle' => 'My Page Title'
];
?>
index.php:
<?php include 'config.php'; ?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $config['pageTitle']; ?></title>
</head>
<body>
<!-- Your page content goes here -->
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
<!-- Your page content goes here -->
</body>
</html>
В вашем конкретном файле представления:
@extends('layout')
@section('title', 'My Page Title')
<!-- Your page-specific content goes here -->
@endsection