This article mainly introduces the Laravel framework template inheritance operation, and analyzes the implementation method of Laravel framework template inheritance and related operation precautions in the form of examples. Friends in need can refer to the following
The examples of this article describe Laravel Framework template inheritance operations. Share it with everyone for your reference, the details are as follows:
Regarding the loading of template inheritance, because we often introduce many styles and other related files in the header, we cannot rewrite them on every page
Laravel is loaded similarly to ThinkPHP. ThinkPHP3.2 uses
<extend name="模板名字" />
placeholders use
<block name="menu"></block>
laravel just uses different English
For example, for a page, we want to introduce the bootstrap page at the head
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" > </head> <body> @yield('content') </body> </html>
Put this file in the root directory of the view or a custom directory, name it app.blade.php and use it in the placeholder
@yield('占位名称')
How to inherit Well, look at the following code
@extends('app') @section('content') 内容 @stop
This can
demonstrate if judgment and loop control
The code in the controller is as follows:
$data = ['a','b','c']; return view('sites.iffor',compact('data'));
Then we can do the following in the view
@extends('app') @section('content') @if(count($data)) <ul> @foreach($data as $v) <li>{{ $v }}</li> @endforeach </ul> @endif @stop
In fact, you don’t need to use if control here. It is mainly to demonstrate how to use it.
The above is the entire content of this article. I hope it will be helpful to everyone’s learning. More For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
The use of action classes in Laravel program architecture design
##
The above is the detailed content of How to take advantage of Laravel framework template inheritance operations. For more information, please follow other related articles on the PHP Chinese website!