My original address: HTTP://WWW.JIANSHU.COM/P/0AA1153EAC22
What does a template inherit? Nature is to enhance the reuse of basic pages, facilitate the organization of the page document, but also easy to change the content used in many places, such as the page header, footer
1. Summary of Usage
@include (' Common.header ') contains a child view
@extends (' article.common.base ') inherit base template
@yield (' content ') View placeholder
Fill in the @section (' content ') @endsection inherit the template back into the view placeholder
{{---comment--}} Use of annotations in blade templates
2. Specific Use
2.1 New Article Base template base.blade.php
Create a new view base template directly using BOOTSTRAP4 template code and CDN
Path resources/views/article/common/base.blade.php
artilce| title in this
{{--Contains page header--}} @include (' Article.common.header ') {{---the content inserted after inheritance-}} @yield (' content ') {{--Contains footer-}} @include (' Article.common.footer ')
2.2. Create sub-view file header and footer
Articles
- (current)
- Write an article
Articles
2.3 To inherit templates for reuse
New home page file in resources/views/article/index.blade.php
@extends (' Article.common.base ') @section (' content ') The homepage of the inherited template is done!
{{--here is blade Comment-}} @endsection
2.4 How do I access it?
Routing and controller coordination are required, here is a simple routing implementation, click on the details, and the rest of the following sections
Write the following code in the app/http/routes.php routing registration file
Route::get ('/', function () { return view (' Article.index ');});
Start your configuration of the laravel running server, such as my directory address under PHP artisan serve
Browser input: localhost:8000, you can see
3.
X BOOTSTRAP4 Start Template code
Hello, world!.