Dominykas55
Dominykas55

Reputation: 1231

How does javascript, jquery work in Symfony2

I am trying to understand how do you use jquery or other scripts in Symfony2. I read the Assets documentation, however that didnt help me that much.

So I have a base.html.twig file in which I add the jquery library and my script file that contains a simple script.

I add it like this:

{% block javascripts %}
    {# Le Javascript #}         
    {% javascripts 
        'bundles/mpFrontend/assets/js/jquery-1.11.2.min.js'         
        'Mp/ShopBundle/Resources/js/scripts.js'   
    %}
        <script src="{{ asset_url }}"></script>       
    {% endjavascripts %}

Now I have a index.html.twig in which I extend the base.html.twig.... Is that all I need? For me the script doesn’t work, do I need to somehow access it in index.html.twig too?

Upvotes: 3

Views: 92

Answers (1)

Michael Sivolobov
Michael Sivolobov

Reputation: 13300

You are messed up with Asstic library and Assets commponent. It is not the same. You should use command:

php app/console assetic:dump

This command will compile your js file and will put it in right place.

Upvotes: 1

Related Questions