Laravel@extends和@include之间有什么区别



我是Laravel的新手,我只想知道@extends@include之间的区别

@extends('tempalate')

我可以使用@include在我的laravel项目中添加模板文件吗。

@include('tempalate')

简单地说:

使用@include('')函数可以包含或添加现有文件。

使用@extends(''),您正在将文件的一部分发送到扩展文件。它通常封装在@section('')函数中。

根据Laravel文档:

Blade的@include指令允许您从在另一个视图中。父级可用的所有变量视图将提供给包含的视图:

<div>
@include('shared.errors')
<form>
<!-- Form Contents -->
</form>
</div>

定义子视图时,使用Blade@extends指令指定子视图应"继承"的布局。查看哪些扩展刀片式布局可能会将内容注入布局的部分使用@section指令。请记住,如上面的示例所示这些部分的内容将使用@产量:

<!-- Stored in resources/views/child.blade.php -->
@extends('layouts.app')
@section('title', 'Page Title')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@endsection
@section('content')
<p>This is my body content.</p>
@endsection

Laravel->刀片模板->包括子视图

最新更新