Blade is the simple, yet powerful templating engine that is included with Laravel. Unlike some PHP templating engines, Blade does not restrict you from using plain PHP code in your templates. In fact, all Blade templates are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. Blade template files use the .blade.php file extension and are typically stored in the resources/views directory.
Layouts
Changing the Layout
If you need to change the layout of your web pages, you can do so by editing the following file:
File: app/View/Components/DefaultLayout.php
You can customize the view file based on the two available default layouts:
There are two primary types of default layouts:
Default Layout
The Default layout can be found in this file:
File: resources/views/layouts/_default.blade.php
The Default layout is a versatile choice suitable for most standard web pages on your website. It provides a clean and straightforward design.
Default Header Layout
The Default Header layout, which is similar to the Default layout but includes a more prominent header, is located in the following file:
This layout is an excellent option when you want to emphasize the header section of your web pages.
Using the Default Layout
To apply the default layout to your web pages, you can use the Blade component x-default-layout. This layout is typically used for standard web pages with the Default or Default Header layout.
Here's an example of how to use the layout:
<x-default-layout>
<!-- Your page content goes here -->
</x-default-layout>
Layout Partials
Partial templates - usually just called "partials" - are another device for breaking the rendering process into more manageable chunks. With a partial, you can move the code for rendering a particular piece of a response to its own file.
To render a partial as part of a view, you use the render method within the view:
@include 'drawers'
This will render a file named _drawers.blade.php at that point within the view being rendered. Note the leading underscore character: partials are named with a leading underscore to distinguish them from regular views, even though they are referred to without the underscore. This holds true even when you're pulling in a partial from another folder:
@include 'partials/drawers'
That code will pull in the partial from app/views/partials/_drawers.blade.php.