// Load the View package require_once 'path/to/view/autoload.php'; // Create a new View instance $view = new \View\View(); // Set the template file $view->setTemplate('path/to/template.php'); // Set the data to be passed to the template $view->setData(['name' => 'John']); // Render the view echo $view->render();
// Load the View package require_once 'path/to/view/autoload.php'; // Create a new View instance $view = new \View\View(); // Set the template file $view->setTemplate('path/to/template.php'); // Set the data to be passed to the template $view->setData([ 'name' => 'John', 'age' => 30, ]); // Add a helper function to the view $view->addHelper('formatAge', function($age) { return $age . ' years old'; }); // Render the view echo $view->render();In this example, we add a helper function to the view which formats the age data. The helper function is defined as an anonymous function and is passed to the `addHelper` method, along with a name for the helper. The helper function can now be used in the template by calling the helper function with the data argument.