What are potential pitfalls when using PHP file includes in templates?

Potential pitfalls when using PHP file includes in templates include security vulnerabilities such as directory traversal attacks and the inclusion of malicious files. To mitigate these risks, it is important to sanitize user input and use absolute file paths when including files.

// Example of including a file with absolute path
include_once $_SERVER['DOCUMENT_ROOT'] . '/path/to/file.php';