Introduction to the blade of Laravel 5 Framework Learning _php Instance

Source: Internet
Author: User

In more than one page we may contain the same content, such as file headers, linked CSS or JS, and so on. We can use the layout file to complete this function.

Let's create a new layout file, such as views/layout.blade.php

<!doctype html>
 
 

We created a puzzled structure, introduced the bootstrap, note @yield is the blade layout placeholder, the future of our page content will be populated here, modify about.blade.php

@extends (' layout ')

@section (' content ')
  
 
 

The code above 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 Contacts () {return
    view (' pages.contact ');
  }

New View pages/contact.blade.php

@extends (' layout ')

@section (' content ')
   
 

Check it out!

In the layout file we can add multiple @yield, such as adding @yield to the layout.blade.php (' footer '):

<!doctype html>
 
 

For example, there is a script in contact.blade.php that can be placed in this section.

@extends (' layout ')

@section (' content ')
   
 

Access to the contact will have a dialog box, and about is still a normal display

Use @if for judgment

@extends (' layout ')

@section (' content ')
  @if ($first = ' Zhang ')
     
 

It can also be equated with the @unless as if!, and @foreach.

  Public function about ()
  {
    $people = [
      ' Zhang San ',
      ' Li si ',
      ' Wang Wu '
    ];
    Return view (' Pages.about ', compact (' People '));
  }
@extends (' layout ')

@section (' content ')
   
 

In one case, the data might come from a database, and the collection might be empty, like this:

Copy Code code as follows:

$people = [];

To handle this situation, add @if processing

@extends (' layout ')

@section (' content ')
  @if (count ($people))
     
 

That ' s better.

The above mentioned is the whole content of this article, hope to be able to learn Laravel5 to be helpful to everybody.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.