What are some best practices for integrating external functions like buildPages into existing PHP scripts using Smarty for templating?

When integrating external functions like buildPages into existing PHP scripts using Smarty for templating, it is important to properly include the necessary files, assign the output of the external function to a Smarty variable, and then display that variable in the template file using Smarty syntax.

<?php
require_once('external_functions.php'); // Include the file containing the external function

// Call the external function and assign the output to a Smarty variable
$pages = buildPages();

// Assign the variable to the Smarty template
$smarty->assign('pages', $pages);

// Display the variable in the template file using Smarty syntax
$smarty->display('template.tpl');
?>