简体   繁体   English

JavaScript中的资产-Symfony2

[英]Assets in JavaScript - Symfony2

I've got a problem, I am using Head.js plugin to import several js files in my template. 我遇到了问题,我正在使用Head.js插件在模板中导入多个js文件。 Each file has a normal path eg assets/js/clock/date.js 每个文件都有一个正常路径,例如assets/js/clock/date.js

The problem is that neither I can use the path directly in importing nor using the twig asset() function to get path to these files. 问题在于,既不能直接在导入中使用路径,也不能使用twig asset()函数来获取这些文件的路径。 As an example this is what I have in a separate js file 例如,这是我在单独的js文件中所拥有的

head.js("../assets/js/newsticker/jquery.newsTicker.js", function() { ... });

How can I get access to the files in folder assets inside a javascript file? 如何获得对javascript文件内文件夹资产中文件的访问?

What you need is a global javascript defined variable in your twig which contains the path of whatever you want to load; 您需要在树枝中定义一个全局javascript变量,其中包含要加载的内容的路径; for example 例如

var generalPath = "{{ asset('path/to/your/asset') }}"; 

now you can call the function as header.js by concatenating with the defined global variable as 现在你可以调用该函数作为header.js通过与定义的全局变量作为串联

head.js(generalPath + 'jquery.cookie.js');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM