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>@verbatim{{ config('app.name') }}@endverbatim</h1>
</body>
</html>
Each file inside your resources/views
directory is a view and is available for use however you like.
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
@verbatim<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>@endverbatim
When defining a child view, use the Blade @verbatim@extends@endverbatim
directive to specify which layout the view should "inherit". Views that extend a Blade layout may inject content into the layout's sections using @verbatim@section@endverbatim
directives. Remember, as seen in the example above, these sections' contents will be displayed in the layout using @verbatim@yield@endverbatim
:
// resources/views/example.blade.php
@verbatim@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@endverbatim
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
@verbatim@include('partials.assets')@endverbatim
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');
@verbatim@foreach($includes->get('assets', []) as $include)
@include $include
@endforeach@endverbatim
We recommend the following conventions as best practice.
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
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}"
}
}
A blank TALL-stack Laravel project with Streams.
The fundamental features and utilities offered by the Streams platform.
A universal and extensible RESTful API for Streams.
Extensible, user-friendly, and performant control panel, components, and services.
Dev tooling for Laravel Streams.