Example of Laravel Framework Template Inheritance Operation
- 2021-10-15 09:56:53
- OfStack
This article illustrates the Laravel framework template inheritance operation. Share it for your reference, as follows:
With regard to the loading of template inheritance, because we often introduce many related files such as styles in the header, we can't rewrite every 1 page
laravel and ThinkPHP are loaded similarly, and ThinkPHP 3.2 uses
<extend name=" Template name " />
Use of placeholder
<block name="menu"></block>
laravel is only different in English
For example, for a page, we want to introduce bootstrap page in the header
<!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>
Place this file in the root of the view or in a custom directory named app. blade. php for use in the placeholder
@yield(' Placeholder name ')
How to inherit, look at the following code
@extends('app')
@section('content')
Content
@stop
In this way,
if Judgment and Cycle Control under Demonstration 1
The code in the controller is as follows l:
$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, mainly to demonstrate how to use it.
More readers interested in Laravel can check the topics of this site: "Introduction and Advanced Tutorial of Laravel Framework", "Summary of Excellent Development Framework of php", "Introduction Tutorial of php Object-Oriented Programming", "Introduction Tutorial of php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
Hope that this article is based on Laravel framework of PHP programming help.