[英]Connect asset twig function with js variable
Hello someone know how to connect asset function with js variable? 您好,有人知道如何使用js变量连接资产功能吗? I have something like that
src="{{ asset('bundles/memes/uploads/') }}"
, and i want to connect this with data['type']
. 我有类似
src="{{ asset('bundles/memes/uploads/') }}"
,我想将它与data['type']
连接起来。 I want in result: 我想要结果:
src="{{ asset('bundles/memes/uploads/#here value of js variable#') }}
Javascript cannot interact directly with server-side languages, since it runs on the user web-browser using the response from the server (basic architecture). Javascript无法直接与服务器端语言进行交互,因为Javascript使用服务器的响应(基本体系结构)在用户Web浏览器上运行。
But you can load whatever you want dynamically using something like this: 但是您可以使用以下方式动态加载任何您想要的内容:
<img id="myImg" src="loading-img.gif" />
<script>
document.getElementById("myImg").src = "{{ absolute_url('bundles/memes/uploads/') }}" + data['type'];
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.