Laravel Blade 自定义指令?循环包括
Laravel Blade custom directive? looped includes
假设我的模板中有以下代码
@foreach($page->getBannersForPosition('bottom') as $banner)
@include('partials.'.$banner->type.'.'.$banner->layout)
@endforeach
但我想要(或类似的东西,简单快捷)
@banners('bottom')
我将如何在 Laravel / Blade 中执行此操作?
我在文档中找到了有关自定义指令的部分,但它对我的帮助不大。
提前致谢!
为什么不将 foreach 移到它自己的部分中。然后你的代码可以读取
@include('banners.bottom')
然后在 banners.bottom.blade 中你会有 foreach 循环
@foreach($page->getBannersForPosition('bottom') as $banner)
@include('partials.'.$banner->type.'.'.$banner->layout)
@endforeach
假设我的模板中有以下代码
@foreach($page->getBannersForPosition('bottom') as $banner)
@include('partials.'.$banner->type.'.'.$banner->layout)
@endforeach
但我想要(或类似的东西,简单快捷)
@banners('bottom')
我将如何在 Laravel / Blade 中执行此操作? 我在文档中找到了有关自定义指令的部分,但它对我的帮助不大。
提前致谢!
为什么不将 foreach 移到它自己的部分中。然后你的代码可以读取
@include('banners.bottom')
然后在 banners.bottom.blade 中你会有 foreach 循环
@foreach($page->getBannersForPosition('bottom') as $banner)
@include('partials.'.$banner->type.'.'.$banner->layout)
@endforeach