(1), first define the route in app\Http\routes.php;
Route::get('view','ViewController@view'); Route::get('article','ViewController@article'); Route::get('layout','ViewController@layout');
(2), and then write the method in http \ controllers \ viewcontroller.php;
public function view(){ return view('index'); } public function article(){ return view('article'); } public function layout(){ return view('layout'); }
(3) Then create a different view file in, with the path: resources\views.
index.blade.php article.blade.php layout.blade.php
Key points:
1. Use the method of include:
1. Create a common directory file under views for storing public files;
Second, put public content under common, such as establishing a header.blade.php in common;
Third, the introduction of public files in the view:
@include('common.header') //This writing method is used to introduce: directory name and common file name.
In addition, if there are different data in the header public area, you can use the following methods to transfer the data:
//Code in the view @ include ('common.header', ['page' = >' detail page']) //code in the //header.blade.php public file {{$ page}}-public part
Then, the above will be output: detailed page-public part.
That is, the delivery was successful.
2, using the way of sub-view, and have the function of transmitting data to each other:
First, create the layouts directory under views, which will lower the main view. Views are sub-views.
Second, create the main view file of home.blade.php under layouts. Can be called by child views.
Third, introduce the main view file into the layout.blade.php in the views directory: by inheritance:
In the home main view:
Yield is an identifier, and the identifier is different variable data. @section('content') I am the content in the master template. @show //When the main view wants to get the variable data of the child view, it must use the show keyword instead of the endsection.
In the child view:
//Inherit the main view.
@extends('layouts.home')
//section can get the contents of the main template.
@section('content')
//parent means that the child template can get the content in the main template.
I am the replacement content of layout 123
@endsection
For more Laravel related technical articles, please visit Laravel tutorial column to learn!
Copyright Description:No reproduction without permission。
Knowledge sharing community for developers。
Let more developers benefit from it。
Help developers share knowledge through the Internet。
Follow us