Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 875
Dominykas55 Avatar asked May 11 '26 00:05

Dominykas55


1 Answers

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.

like image 81
Michael Sivolobov Avatar answered May 12 '26 14:05

Michael Sivolobov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!