Laravel 5 Framework Learning Blade Introduction, Laravelblade
In multiple pages we may contain the same content, such as the file header, linked CSS or JS. We can use the layout file to complete this function.
Let's create a new layout file, such as views/layout.blade.php
Document
@yield (' content ')
We created a puzzled structure, introduced the bootstrap, note that @yield is the blade layout placeholder, the future of our page content will be populated here, modified about.blade.php
@extends (' layout ') @section (' content ') About {{$first}} {{$last}}
@stop
The above code indicates that we use the layout file layout.blade.php and then add content to the contents section.
Add in routes.php:
Route::get (' About ', ' pagescontroller@about '); Route::get (' Contact ', ' pagescontroller@contact ');
Add in pagescontroller.php:
Public Function Contact () { return view (' Pages.contact '); }
New View pages/contact.blade.php
@extends (' layout ') @section (' content ') Contact me!
@stop
Check it out!
In the layout file we can add multiple @yield, such as adding @yield (' footer ') to the layout.blade.php:
Document
@yield (' content ') @yield (' footer ')
For example, there is a script in contact.blade.php that can be placed in this section.
@extends (' layout ') @section (' content ') Contact me!
@stop @section (' footer ') @stop
Access to the contact will have a dialog box, and about is still a normal display
Use @if to judge
@extends (' layout ') @section (' content ') @if ($first = ' Zhang ') Hello, Zhang
@else Hello, nobody.
@endif @stop
can also be equated with the same @unless if!, and @foreach.
Public function about () { $people = [ ' Zhang San ', ' Li si ', ' Wang Wu ' ]; Return view (' Pages.about ', compact (' People ')); } @extends (' layout ') @section (' content ') Person:
@foreach ($people as $person)
- {{$person}}
@endforeach
@stop
In one case, the data might be from the database, and the collection might be empty, like this:
Copy the Code code as follows:
$people = [];
To handle this situation, add @if processing
@extends (' layout ') @section (' content ') @if (count ($people)) Person:
@foreach ($people as $person)
- {{$person}}
@endforeach
@endif
Other Info
@stop
That ' s better.
The above is the whole content of this article, I hope to be able to learn Laravel5 to help you.
http://www.bkjia.com/PHPjc/980216.html www.bkjia.com true http://www.bkjia.com/PHPjc/980216.html techarticle Laravel 5 Framework Learning Blade Introduction, Laravelblade on multiple pages we may contain the same content, such as the file header, linked CSS or JS. We can use the layout file to finish ...