Home > Backend Development > PHP Tutorial > How to take advantage of Laravel framework template inheritance operations

How to take advantage of Laravel framework template inheritance operations

不言
Release: 2023-03-31 14:20:01
Original
1962 people have browsed it

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="模板名字" />
Copy after login

placeholders use

<block name="menu"></block>
Copy after login

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(&#39;content&#39;)
</body>
</html>
Copy after login

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(&#39;占位名称&#39;)
Copy after login

How to inherit Well, look at the following code

@extends(&#39;app&#39;)
@section(&#39;content&#39;)
内容
@stop
Copy after login

This can

demonstrate if judgment and loop control

The code in the controller is as follows:

$data = [&#39;a&#39;,&#39;b&#39;,&#39;c&#39;];
  return view(&#39;sites.iffor&#39;,compact(&#39;data&#39;));
Copy after login

Then we can do the following in the view

@extends(&#39;app&#39;)
@section(&#39;content&#39;)
  @if(count($data))
    <ul>
    @foreach($data as $v)
      <li>{{ $v }}</li>
    @endforeach
    </ul>
  @endif
@stop
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template