如何使用laravels刀片添加动态图像src [英] how to add a dynamic image src with laravels blade

查看:88
本文介绍了如何使用laravels刀片添加动态图像src的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单.我在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆