Laravel 5.4刀片引入了组件&插槽的概念 - 但我看不到他们添加的是传统的@include。据我所知,有分量/插槽,你这样做:Laravel Blade - @ slot/@组件的优点vs @include?
在模板组件tpl.blade.php:
<div class='container'>
<h1>{{$slot1}}</h1>
<h2>{{$slot2}}</h2>
</div>
使用插槽页面模板,你这样做:
@component('component-tpl')
@slot('slot1')
The content of Slot 1
@endslot
@slot('slot2')
The content of Slot 2
@endslot
@endcomponent
什么功能确实提供了超过老版本的功能:
@include('component-tpl',['slot1'=>'The content of Slot 1',
'slot2'=>"The content of Slot 2"])
使用完全相同的'component-tpl.blade.php'Bl ade模板?
我缺少什么?感谢您的任何见解。
克里斯
'@ component'似乎很好,如果你正在开始一个新的项目,但如果一个人已经拥有一个已经使用了大量'@ include'的现有项目,那么似乎试图记住哪些部分是@ component'和哪些部分是'@ include'将是混乱的。 –