What are common pitfalls when using a template system in PHP, as seen in the code provided?
Common pitfalls when using a template system in PHP include not properly escaping user input, not separating logic from presentation, and not utilizing caching to improve performance. To solve these issues, always sanitize and escape user input before displaying it in templates, follow the MVC pattern to separate logic from presentation, and implement caching mechanisms to reduce the load on the server.
// Example of properly escaping user input in a template
$userInput = "<script>alert('XSS attack');</script>";
echo htmlspecialchars($userInput, ENT_QUOTES, 'UTF-8');