💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Blade 是 Laravel 所提供的一个简单却又非常强大的模板引擎。不像控制器页面布局,Blade 是使用 `模板继承(template inheritance)` 和 `区块(sections)`。所有的 Blade 模板后缀名都要命名为 `.blade.php`。 定义一个 Blade 页面布局 ~~~ <!-- Stored in resources/views/layouts/master.blade.php --> <html> <head> <title>App Name - @yield('title')</title> </head> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> ~~~ 在视图模板中使用 Blade 页面布局 ~~~ @extends('layouts.master') @section('title', 'Page Title') @section('sidebar') @@parent <p>This is appended to the master sidebar.</p> @stop @section('content') <p>This is my body content.</p> @stop ~~~ 请注意 如果视图 `继承(extend)` 了一个 Blade 页面布局会将页面布局中定义的区块用视图的所定义的区块重写。如果想要将页面布局中的区块内容也能在继承此布局的视图中呈现,那就要在区块中使用 `@@parent` 语法指令,通过这种方式可以把内容附加到页面布局中,我们会在侧边栏区块或者页脚区块看到类似的使用。 有时候,如您不确定这个区块内容有没有被定义,您可能会想要传一个默认的值给 `@yield`。您可以传入第二个参数作为默认值给 `@yield`: ~~~ @yield('section', 'Default Content') ~~~