1

I've got a problem, I am using Head.js plugin to import several js files in my template. Each file has a normal path e.g. 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. As an example this is what I have in a separate js file

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

How can I get access to the files in folder assets inside a javascript file?

10
  • Provide your code; Why you cannot use asset() function? I guess you are referencing those javascript file in a twig file Commented May 26, 2014 at 18:45
  • for example I've got something like that: <!-- language: lang-js --> head.js("../assets/js/newsticker/jquery.newsTicker.js", function() { var nt_title = $('#nt-title').newsTicker({ row_height: 18, max_rows: 1, duration: 5000, pauseOnHover: 0 }); }); Commented May 26, 2014 at 18:46
  • Edit your question and show us your current code, where you are importing the JavaScript files. Commented May 26, 2014 at 18:48
  • how can I format js code to show you? Commented May 26, 2014 at 18:51
  • Indent your code by 4 spaces: stackoverflow.com/help/formatting Commented May 26, 2014 at 18:56

1 Answer 1

2

What you need is a global javascript defined variable in your twig which contains the path of whatever you want to load; 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

head.js(generalPath + 'jquery.cookie.js');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.