Laravel - Difference between @yield and @section?

后端 未结 5 1297
鱼传尺愫
鱼传尺愫 2021-01-31 03:33

From the Laravel docs, you can include \'sections\' inside layouts using two methods:


    
        @section(\'sidebar\')
            Thi         


        
5条回答
  •  迷失自我
    2021-01-31 03:44

    This line clears out the confusion: "Note that views which extend a Blade layout simply override sections from the layout. Content of the layout can be included in a child view using the @parent directive in a section".

    So, if you already have a @section defined in the master layout, it will be overriden unless you specify @parent inside the child layout's @section.

    But for @yield, it always gets the section from the child layout. That means it always overrides the @yield part, even if it has a default defined as @yield('section', 'Default Content') .

    I hope that clears your confusion. Let me know if you have more questions. Thanks

提交回复
热议问题