What best practices should be followed when setting the root directory for templates in PHP?

When setting the root directory for templates in PHP, it is important to use an absolute path to ensure that the templates can be accessed correctly regardless of the current working directory. This helps prevent issues with file path resolution and ensures that the templates are loaded consistently across different environments. Additionally, it is recommended to define a constant for the root directory to make it easier to reference in your code.

// Define a constant for the root directory of your project
define('ROOT_DIR', __DIR__);

// Set the root directory for templates
$templateDir = ROOT_DIR . '/templates/';