Views

Views contain the HTML served by the frontend of your application. You can find and define views in the resources/views directory. A simple view might look something like this:

// resources/views/welcome.blade.php
<html>
    <body>
        <h1>{{ config('app.name') }}</h1>
    </body>
</html>

Each file inside your resources/views directory is a view and is available for use however you like.

Layouts

Layouts are the outer structural foundation of your application's HTML. It is considered best practice to leverage layouts via view inheritance to abstract your view presentation.

// resources/views/layouts/default.blade.php
<html>
    <head>
        <title>App Name - @yield('title')</title>
    </head>
    <body>
        @section('sidebar')
            This is the default sidebar.
        @show

        <div class="container">
            @yield('content')
        </div>
    </body>
</html>

Extending Layouts

When defining a child view, use the Blade @extends directive to specify which layout the view should "inherit". Views that extend a Blade layout may inject content into the layout's sections using @section directives. Remember, as seen in the example above, these sections' contents will be displayed in the layout using @yield:

// resources/views/example.blade.php
@extends('layouts.default')

@section('title', 'Example Title')

@section('sidebar')
    @parent

    <p>This is appended to the default sidebar.</p>
@endsection

@section('content')
    <p>This is the content.</p>
@endsection

Partials

Partials are reusable views intended to be included in many other views and even within other partials. You can use any view as a "partial" by using the include directive.

// Import /resources/views/partials/assets.blade.php
@include('partials.assets')

Includes

Includes are like named slots that can be accessed outside of, and prior to, the view layer.

use Streams\Core\Support\Facades\Includes;

Includes::include('assets', 'partials.scripts');
@foreach($includes->get('assets', []) as $include)
    @include $include
@endforeach

Conventions

We recommend the following conventions as best practice.

Naming

Organizing

Below is an excellent example of organizing utilitarian views like layouts and partials. These views are used for application structure and DRY'ing up views.

resources/views/
|-- partials/
|   |-- head.blade.php
|   |-- footer.blade.php
|   |-- navigation.blade.php
|-- layouts/
|   |-- amp.blade.php
|   |-- default.blade.php
|   |-- alternate.blade.php

Stream Views

Organizing stream views by stream can not only be automatically detected but bring order to large applications. You can even bundle stream specific partials and layouts within the stream directories to separate them from similar type views intended for global use, as shown above.

resources/views/
|-- contacts/
|   |-- index.blade.php
|   |-- view.blade.php
|   |-- vcard.blade.php

The above views correlate to the below routing example.

// streams/contacts.json
{
    "routes": {
        "index": "contacts",
        "view": "contacts/{id}",
        "vcard": "contacts/vcard/{id}"
    }
}