Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试从 javascript 文件中动态加载图像。
如何使用 Assets(或 FOSJsRoutingBundle)加载它,而无需将 .js 文件的代码粘贴到模板中?
您可以发布 PHP 生成的 JS 变量,然后在您的 JS 文件中使用它。
例如:
<script> var image_path = '{{ asset('your/path/to/image') }}'; </script>
如果您在通常包含 JS 文件的部分中需要此路径,则始终可以使用树枝块。