如何使用laravels刀片添加动态图像src [英] how to add a dynamic image src with laravels blade
问题描述
我的问题很简单.我在laravel中使用blade来显示类似的图像
My question is very simple. i use blade in laravel to show the images like
<img src="{{asset('assets/images/image.jpg')}}">
但是如果我的图像是动态的,如:
but what if my image is dynamic like:
<img src="{{asset('assets/images/$imgsrc')}}">
我不能使用
<img src="{{asset('assets/images/{{ $imgsrc')}}">
因为那我将以:
<img src="http://localhost/assets/images/{{ $imgsrc">
如何在刀片{{}}调用中调用$ variable?
How can i call to a $variable in a blade {{}} call?
推荐答案
如何
<img src="{{asset('assets/images/').'/'.$imgsrc}}">
编辑
当您需要打印多个可能存在变量,函数的字符串时,需要将它们串联起来
when you need printing more than one strings where there may be variables,functions... you need to concatenate them
asset('assets/images/')
也等同于asset('assets/images')
,因此您需要在打印变量$imgsrc
Also asset('assets/images/')
is equivalent to asset('assets/images')
so you need to add /
before printing your variable $imgsrc
最后,在Blade {{"foo"}}
中等效于<?php echo "foo" ?>
Finally, in Blade {{"foo"}}
is equivalent to <?php echo "foo" ?>
这篇关于如何使用laravels刀片添加动态图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!