What are the best practices for integrating PHP into TPL files?

When integrating PHP into TPL files, it is important to separate logic from presentation to maintain clean and readable code. One way to achieve this is by using PHP to process data and functions separately, then passing the processed data to the TPL file for display. This helps to improve code organization and maintainability.

<?php
// Process data and functions in PHP file
$data = ['John', 'Doe', 'Jane', 'Smith'];
$processedData = [];

foreach ($data as $name) {
    $processedData[] = strtoupper($name);
}

// Pass processed data to TPL file for display
include 'template.tpl';
?>
```

In the TPL file (template.tpl):
```html
<!DOCTYPE html>
<html>
<head>
    <title>Processed Data</title>
</head>
<body>
    <ul>
        <?php foreach ($processedData as $name) : ?>
            <li><?php echo $name; ?></li>
        <?php endforeach; ?>
    </ul>
</body>
</html>