【原创】Laravel中的模板

语法

<!DOCTYPE html> <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');
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注