Laravel - Difference between @yield and @section?

后端 未结 5 1377
鱼传尺愫
鱼传尺愫 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:43

    Basically yield('content') is a marker. For example, in the tag if you put a yield('content'), your saying this section has the name of content and by the way, you can name inside of the parenthesis anything you want. it doesn't have to be content. it can be yield('inside'). or anything you want.

    And then in the child page where you want to import html from your layout page, you just say section('name of the section').
    for example, if you have marked your header in your layout page as yield('my_head_band') <-- or anything else you want, then in your child page you just say @section('my_head_band').

    This would import the header from the layout page into your child page. vice versa with your body section which in this case was named as content.

    Hope this helps.

提交回复
热议问题