How can the EVA principle be applied to separate HTML output from PHP logic in a PHP script?
The EVA (Separation of Concerns) principle suggests separating the HTML output from PHP logic for better maintainability and readability of code. One way to achieve this is by using a template engine like Twig or Smarty to handle the HTML rendering, while keeping the PHP logic separate in the backend.
<?php
// PHP logic
$data = ['name' => 'John Doe', 'age' => 30];
// Load the template engine
require_once 'vendor/autoload.php';
$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);
// Render the template with the data
echo $twig->render('index.html', $data);
?>