0

I have a Symfony2 project and I have some JavaScript code to be executed.

Where should the .js file be stored in the project and how to call this file (instead of putting the entire script in the .twig)?

1 Answer 1

2

Put it in web/js, then access it in your html via:

<script src="{{ asset('js/script.js') }}"></script>

or consider using Assetic.

Sign up to request clarification or add additional context in comments.

2 Comments

PS: One more question, I am getting an javascript error: ReferenceError: $ is not defined when I am trying to use $(document).ready(function(){
You need to import jQuery before you execute any other scripts requiring it.

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.