View Layouts

    Layouts are views like any other. The only difference is their intended usage. Layouts are the only viewfiles that would make use of the method. This method acts as a placeholder for content.

    The renderSection() method only has one argument - the name of the section. That way any child views knowwhat to name the content section.

    1. <?= $this->extend('default') ?>

    The extend method takes the name of any view file that you wish to use. Since they are standard views, they willbe located just like a view. By default, it will look in the application’s View directory, but will also scanother PSR-4 defined namespaces. You can include a namespace to locate the view in particular namespace View directory:

    All content within a view that extends a layout must be included within and endSection() method calls.Any content between these calls will be inserted into the layout wherever the call thatmatches the section name exists.:

    1. <?= $this->extend('default') ?>
    2.  
    3. <?= $this->section('content') ?>
    4. <h1>Hello World!</h1>

    Rendering the view and it’s layout is done exactly as any other view would be displayed within a controller:

    The renderer is smart enough to detect whether the view should be rendered on its own, or if it needs a layout.

    1. <?= $this->extend('default') ?>
    2.  
    3. <?= $this->section('content') ?>
    4. <h1>Hello World!</h1>
    5.  
    6. <?= $this->include('sidebar') ?>

    When calling the include() method, you can pass it all of the same options that can when rendering a normal view, includingcache directives, etc.