语法
<html> <head> <title>Weibo App</title> </head> <body> @yield('content') </body> </html>
@extends('layouts.default') @section('content') <h1>主页</h1> @stop
以上代码使用 extends
来继承视图, section
和 stop
之间的代码都会被嵌入到父视图的 content
块中。
yield 设置默认值
<title>@yield('title', 'Weibo App')</title>
@extends('layouts.default') @section('title', '帮助') @section('content') <h1>帮助页</h1> @stop
当
@section
传递了第二个参数时,就不需要用@stop
标识来标记结束位置。
也可以在 @yield
后面进行拼接,例如:
<title>@yield('title', 'Weibo App') - Laravel 新手入门教程</title>
局部视图
局部视图通常命名时前面加下划线 _
,例如: _header.blade.php
。 引入局部视图使用 @include
,例如:
@include ('layouts.header');
更多精彩内容:各种AI课程、技能课程、黑科技软件、网站小程序源码、副业小项目、PPT模板等精品素材、电商课程、推广引流课程等,尽在 天边资源网 。