How can the use of a template engine like Smarty improve code organization and maintainability in PHP projects?

Using a template engine like Smarty can improve code organization and maintainability in PHP projects by separating the presentation layer from the business logic. This allows developers to focus on writing clean and maintainable code without mixing HTML and PHP code. Additionally, templates can be easily reused and modified without affecting the underlying logic.

<?php
// Include Smarty library
require_once('smarty/Smarty.class.php');

// Create a new Smarty object
$smarty = new Smarty;

// Assign variables to the template
$smarty->assign('name', 'John Doe');
$smarty->assign('age', 30);

// Display the template
$smarty->display('index.tpl');
?>