How can PHP be effectively used as a template engine to render different page content based on user requests?

To effectively use PHP as a template engine to render different page content based on user requests, you can create separate template files for each type of content and use PHP to include the appropriate template based on the user's request. This can be achieved by passing a parameter in the URL or using a session variable to determine the content to be displayed.

<?php
// Check the user's request
$page = isset($_GET['page']) ? $_GET['page'] : 'home';

// Include the appropriate template based on the user's request
switch ($page) {
    case 'home':
        include 'templates/home.php';
        break;
    case 'about':
        include 'templates/about.php';
        break;
    case 'contact':
        include 'templates/contact.php';
        break;
    default:
        include 'templates/error.php';
        break;
}
?>