The view file

You can only have one view template file at once. It's used for your main content and makes it possible for you to easily change the layout depending on the subject, for example, a blog with a sidebar or regular pages with sections. It does not require much code, and you could add partials directly inside it without any HTML code. However, it is highly recommended that you use it because there will come a time when you will need it. The following is the default view file and will be loaded if you do not manually change it, which is possible in your controllers and middleware.

Let´s take a look at the resources/views/main.php file.

<?php echo $this->partial("main")->get(); ?>
<?php echo $this->partial("form")->get(); ?>

Change view - example 1

The bellow example expects that the file "resources/views/blog.php" exists.

class Blog
    private $provider;
    public function __construct(Provider $provider)
        $this->provider = $provider;
    public function posts(ResponseInterface $response, RequestInterface $request): ResponseInterface
        // Your post partials here
        return $response;

Last updated