I'd like to split my layouts into partials.
I'm creating a default blade layout.
The file is called default.blade.php, and lives in the layout
folder.
Also under the layout folder is include
.
In this dir, I have head.blade.php
I would like to call 'head' from 'default'.
Every one of these fails and returns an error when debug is turned on:
@include('include/head'), @include('include/head.blade.php'), @include('include/head.blade.php')
I have copied head.blade.php into the same folder as default.blade.php, and still get errors.
Laravel Blade Partials A blade partial is similar to an include or require in PHP. It's an easy way to include contents of another file inside of a template. A PHP include would look something like 'include file. php' whereas a blade @include looks like @include('partials. file.
The blade templates are stored in the /resources/view directory. The main advantage of using the blade template is that we can create the master template, which can be extended by other files.
One of blade directive @stack('scripts') is very helpful when you have javascript need to execute in the child page. I create a fresh Laravel installation to demo an example. I have to make auth scaffolding with laravel/ui package because I'm using Laravel 6.
nl2br — Inserts HTML line breaks before all newlines in a string. Laravel helper provide many functionalities and you can use e Laravel helper function to purify your html before showing line breaks. You need to do the escaping first using e() and then after apply nl2br() function.
You need to give the full path relative to your view folder. Try doing this :
@include('layout.include.head')
Keep in mind that Laravel uses dot notation to organize the templates and their parts.
So, the main.blade.php
template in your main /views
folder should be included directly:
@include ('main')
A main.blade.php
template in a, e.g. /views/layouts
folder should be called as:
@include ('layouts.main')
and so on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With