What are the advantages and disadvantages of creating a custom template engine versus using existing ones like Twig in PHP?

When deciding between creating a custom template engine or using existing ones like Twig in PHP, it's important to consider the trade-offs. Advantages of creating a custom template engine include complete control over the syntax and functionality, tailored specifically to your project's needs. On the other hand, using existing template engines like Twig can save time and effort by leveraging a well-tested and widely-used solution, with built-in features like caching and security measures.

// Example of using Twig template engine in PHP
require_once 'vendor/autoload.php';

$loader = new \Twig\Loader\FilesystemLoader('templates');
$twig = new \Twig\Environment($loader);

echo $twig->render('index.html', ['name' => 'John']);