我在刀片模板中将图像设置为数组内部属性时遇到了一些问题。通常我们在HTML代码中使用它
<div data-zs-src='["fronend/image/1.jpg", "fronend/image/2.jpg", "fronend/image/3.jpg"]' data-zs-overlay="dots">
<!--some code-->
</div>
任何人都可以告诉我如何在Blade模板中执行此操作吗?
您可以将数组作为变量$my_array
发送到刀片视图,然后将其附加到属性。
在行动:
$my_array = "[".implode(',', ["fronend/image/1.jpg", "fronend/image/2.jpg", "fronend/image/3.jpg"])."]";
在视图中:
<div data-zs-src='{{ $my_array }}' data-zs-overlay="dots">
如果你是静态数组,并且直接调用视图,则可以在刀片内定义变量,例如:
@php $my_array = "[".implode(',', ["fronend/image/1.jpg", "fronend/image/2.jpg", "fronend/image/3.jpg"])."]" @endphp
<div data-zs-src='{{ $my_array }}' data-zs-overlay="dots">
您可以使用刀片标签开头的escape
符号在刀片模板中添加@
数据。
所以在你的情况下:
<div data-zs-src='@{{ ["fronend/image/1.jpg", "fronend/image/2.jpg", "fronend/image/3.jpg"] }}' data-zs-overlay="dots">
<!--some code-->
</div>
刀片不会处理此标记中的所有数据。