Laravel5 introduction to Blade, laravelblade. Introduction to Blade in Laravel5 framework learning. in multiple pages, laravelblade may contain the same content, such as file headers, linked css or js. We can use the layout file to complete the Blade introduction of Laravel 5 framework learning, laravelblade
Multiple pages may contain the same content, such as file headers, 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 have created an uncertain structure and introduced bootstrap. Note that @ yield is the placeholder for the blade layout. in the future, our page content will be filled here and we will modify 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 the content in the content section.
Add the following in routes. php:
Route::get('about', 'PagesController@about');Route::get('contact', 'PagesController@contact');
Add the following in PagesController. php:
public function contact() { return view('pages.contact'); }
Create view pages/contact. blade. php
@extends('layout')@section('content') Contact Me!@stop
Check it out!
You can add multiple @ yield in the layout file. for example, add @ yield ('footer ') in layout. blade. php '):
Document
@yield('content')
@yield('footer')
For example, you can put a script in contact. blade. php.
@extends('layout')@section('content') Contact Me!@stop@section('footer') 《script》 alert('Contact from scritp') 《script》@stop
A dialog box is displayed when you access contact, while about is still displayed normally.
Use @ if to determine
@extends('layout')@section('content') @if ($first = 'Zhang') Hello, Zhang @else Hello, nobody @endif@stop
It can also be seen as @ unless equivalent to 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 may come from the database, and the set may be empty, such:
The code is as follows:
$ People = [];
To handle this situation, add @ if
@extends('layout')@section('content') @if (count($people)) Person:
@foreach($people as $person)
- {{ $person }}
@endforeach
@endif Other info@stop
That's better.
The above is all the content of this article, hoping to help you learn laravel5.
Http://www.bkjia.com/PHPjc/980216.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/980216.htmlTechArticleLaravel 5 framework learning Blade introduction, laravelblade in multiple pages we may contain the same content, such as file headers, links to css or js and so on. We can use the layout file to finish...