【发布时间】:2021-07-13 15:46:55
【问题描述】:
在 laravel 中,我想访问插槽/插槽的索引... 例如在我的 index.blade.php 我有:
<x-steps>
<x-step-card title="step 1" text="Example text for step 1" ></x-step-card>
<x-step-card title="step 2" text="Example text for step 2" ></x-step-card>
<x-step-card title="step 3" text="Example text for step 3" ></x-step-card>
</x-steps>
在我的 steps.blade.php 我有:
<div class="container">
{{$slot}}
</div>
我想将每个插槽项的索引传递给我的 step-card 组件,尽管 steps.blade.php... 这样的东西会很好:
<div class="container">
@foreach($slots as $slot)
<x-step-card step="{{ $loop->index }}" title="{{$slot->title}}" text="{{$slot->text}}"></x-step-card>
@endforeach
</div>
问题是 $slots 不是变量 我不能循环 $slot 因为它返回一个 已经渲染的 html 字符串。
PS: foreach 代码是我想做的一个例子,但它不起作用,因为你不能循环 $slot.. 并且 $slots 不存在。
编辑:我正在使用带有 ckeditor 的背包 cms,我想在渲染之前将另一个属性注入我的 x-step-card 组件。
谢谢。
【问题讨论】:
标签: php laravel laravel-blade