我正在研究 Blade 如何实现 @section,但它的工作方式与我习惯的 Twig 略有不同。看来你不能将 @sections 嵌套在一起。
示例:
_layout.blade.php(基本布局文件)
<html>
//favicons
//meta content
//other basic shizzle
<head>
<title>overal</title>
</head>
<body>
@yield('body_content')
</body>
</html>
website.blade.php(具体实现)
@extend('_layout.blade.php')
@section('body_content')
<div class="">
website-header
</div>
<div class="main">
@section('navigation')
<nav>website navigation</nav>
@endsection
<div class="website">
{-- the actual content --}
@yield('content')
</div>
</div>
@endsection
blog.blade.php(博客页面的实现)
@extend('website.blade.php')
@section('content')
blog-items
@endsection
faq.blade.php(常见问题页面的实现)
@extend('website.blade.php')
{{-- we don't want the navigation here or want something different --}}
@section('nav')@endsection
@section('content')
faq-items
@endsection
我无法使用 @includes 解决这个问题,因为我希望能够灵活地确定 subview 中的子子部分并覆盖其内容。
最佳答案
没关系,这是可能的 困扰我的是我的编辑(PhpStorm)。您可以将@section嵌套在一起,并在扩展模板中覆盖/重新定义它们^^
W00000t
关于laravel - Blade 中的嵌套部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48425076/