In what scenarios would it be recommended to use a template engine to avoid mixing PHP and HTML in code?

When working on a project where PHP and HTML are mixed together, it can become difficult to maintain and update the code. Using a template engine can help separate the presentation layer (HTML) from the logic layer (PHP), making the code more organized and easier to manage. This can also improve code readability and reusability.

<?php
// Include the template engine library
require_once('template_engine.php');

// Initialize the template engine
$template = new TemplateEngine();

// Assign variables to be used in the template
$template->assign('title', 'Welcome to our website');
$template->assign('content', 'This is the content of the page');

// Load and display the template file
$template->display('template_file.php');
?>