What are some common pitfalls when working with TPL files in PHP?

One common pitfall when working with TPL files in PHP is not properly escaping variables before outputting them, which can lead to potential security vulnerabilities such as cross-site scripting attacks. To solve this issue, always use PHP's htmlspecialchars function to escape variables before displaying them in your TPL files.

// Example of properly escaping variables in a TPL file
$name = "<script>alert('XSS attack');</script>";
$escapedName = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
echo "<p>Welcome, $escapedName!</p>";