What are some potential pitfalls when using a template engine in PHP?

One potential pitfall when using a template engine in PHP is the risk of code injection if user input is not properly sanitized. To prevent this, always use proper escaping functions provided by the template engine or manually sanitize user input before passing it to the template.

// Example of properly sanitizing user input before passing it to a template engine
$user_input = $_POST['user_input'];
$sanitized_input = htmlspecialchars($user_input, ENT_QUOTES, 'UTF-8');
$template_engine->assign('user_input', $sanitized_input);