What are the advantages and disadvantages of using session variables to store templates in PHP, especially when dealing with multiple templates in a project?

Using session variables to store templates in PHP can be advantageous as it allows for easy access to templates across multiple pages without the need to repeatedly include them. However, this approach can lead to increased server load and memory usage, especially when dealing with multiple templates in a project. It is important to carefully consider the trade-offs and potential performance implications before implementing this solution.

<?php
// Start the session
session_start();

// Store template in session variable
$_SESSION['template'] = 'template_name.php';

// Retrieve template from session variable
$template = $_SESSION['template'];

// Include the template file
include($template);
?>