$app->get('/', function ($request, $response, $args) { $data = ['title' => 'Homepage', 'body' => 'Welcome to my website!']; return $this->view->render($response, 'template.php', $data); });
$app->get('/about', function ($request, $response, $args) { $data = ['title' => 'About', 'body' => 'This is the about page.']; return $this->view->render($response, 'layout.php', ['data' => $data]); });In this example, we define a route for the 'about' page and use template inheritance to create a unified layout for all pages. The 'layout.php' template defines the overall page structure, and the 'about.php' template extends it with specific content. In both examples, we use the `$this->view->render()` method to render a template. The first argument is the response object, the second argument is the name of the template file, and the third argument is an associative array of data to pass to the template. Overall, Slim view is a useful package library for PHP developers who want to create dynamic and flexible web applications using Slim.