Nesting sections in Blade

…衆ロ難τιáo~ 提交于 2021-01-28 08:56:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!