[英]How can I store ternary operator to the html element in laravel blade
I have an html element, for example it would be an image, and I want to check my entity for some conditions and depending on this add or do not some class to this element, like this: 我有一个html元素,例如它将是一个图像,并且我想检查我的实体的某些条件,并根据此元素的此类添加或不添加类,如下所示:
<div class="btn btn-default">
{{ HTML::image('//image.png', '', array("class" => "{{{in_array($prod->id, $deleted) ? 'hidden':''}}}")) }}
</div>
So, then I have an exception on this line: "Array to string conversion" 所以,那么我在这一行有一个例外: “数组到字符串的转换”
Tell me, please, how can I avoid it? 请告诉我,如何避免呢?
You should use: 您应该使用:
<div class="btn btn-default">
{{ HTML::image('//image.png', '', array("class" => in_array($prod->id, $deleted) ? 'hidden':'')) }}
</div>
Of course $prod->id
must be single element (string, integer, float) and $deleted
must be array
here. 当然,
$prod->id
必须是单个元素(字符串,整数,浮点数),而$deleted
必须在此处为array
。 If you still have this message, you need to check types of $prod->id
and $deleted
. 如果仍然显示此消息,则需要检查
$prod->id
和$deleted
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.