问题
I'm looking at how Blade implements the @section, but it works a little different than I'm used to with Twig. It seems that you can't nest @sections in each other.
Example:
_layout.blade.php (basic layout file)
<html>
//favicons
//meta content
//other basic shizzle
<head>
<title>overal</title>
</head>
<body>
@yield('body_content')
</body>
</html>
website.blade.php (specific implementation)
@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 (implementation for the blog-page)
@extend('website.blade.php')
@section('content')
blog-items
@endsection
faq.blade.php (implementation for the faq-page)
@extend('website.blade.php')
{{-- we don't want the navigation here or want something different --}}
@section('nav')@endsection
@section('content')
faq-items
@endsection
And I can't solve it with @includes, since I want the flexibility to be able to determine sub-sub sections in sub-views and overwrite their content.
回答1:
Never mind, this is possible It was my editor (PhpStorm) that was bugging me. You CAN nest @section in each other and overwrite/redefine them in extended templates ^^
W00000t
来源:https://stackoverflow.com/questions/48425076/nesting-sections-in-blade