0

Not sure what's wrong but I can't include javascript and/or stylesheet files. Using Symfony3

{% block javascripts %}
    {% javascripts
        '@AppBundle/assets/js/jquery.js'
        '@AppBundle/assets/bootstrap/js/bootstrap.min.js'
    %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

{% endblock %}

getting this error: Variable " asset_url" does not exist in security/login.html.twig at line 32

Diamonte
  • 393
  • 7
  • 22
  • Could you try to add `output='js/compiled/app.js'` at the end of (and inside of it) `javascripts`? It would be just above ` – Kamil Jan 12 '16 at 12:35
  • `{% block javascripts %} {% javascripts output='js/compiled/app.js'` no luck yet – Diamonte Jan 12 '16 at 12:42
  • Where are your files located? They are typically in `@AppBundle/Resources/public` instead of `@AppBundle/assets` – Jason Roman Jan 12 '16 at 17:21

1 Answers1

0

Overall, the code should probably look like this:

{% block javascripts %}
    {% javascripts
        '@AppBundle/assets/js/jquery.js'
        '@AppBundle/assets/bootstrap/js/bootstrap.min.js'
        output='js/compiled/app.js' %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}
{% endblock %}

If it doesn't work then make sure that path to these files is correct.

Kamil
  • 91
  • 1
  • 6
  • well, lets make it simple, i should use just js/.js if they are in web folder ? – Diamonte Jan 12 '16 at 13:12
  • Yes. For example `'js/jquery.js'` or `'bootstrap/js/bootstrap.min.js'` (if it also is in the web folder and has such structure) – Kamil Jan 12 '16 at 13:24
  • `{% block javascripts %} {% javascripts output='js/compiled/app.js' 'js/jquery.js' %} {% endjavascripts %} {% endblock %}` I have now and triple checked the jquery.js file exists in web/js/ folder – Diamonte Jan 12 '16 at 13:45
  • Try to move output to the end of `javascripts` as I did – Kamil Jan 12 '16 at 13:51
  • Try to move it outside of the block and see if anything changes – Kamil Jan 12 '16 at 13:55
  • no luck, when I do `{% block javascripts %} {% endblock %}` it loads page correctly, but when I see source and try to open the file, its empty, so I think It can't find the file. It's placed in web/js/jquery.js – Diamonte Jan 12 '16 at 15:11
  • I assume that you run it with built-in Web Server, does it have permission to access all of these files? Because I suspect that problem lies somewhere else, as my code should load these assets without any problems. – Kamil Jan 12 '16 at 15:33
  • it should have permissions, tho if u know what per folder need I can check, it can write cache etc tho... – Diamonte Jan 12 '16 at 18:49
  • I have now `{% block javascripts %} {% javascripts 'js/jquery.js' output='js/compiled/app.js' %} {% endjavascripts %} {% endblock %}` and there is app_jquery_1.js in web/js/compiled/ folder (it was app.js before but I renamed it). I used php bin/console cache:clear --env=prod to dumb these. Don't know whats wrong but I can't get JS or CSS to work with symphony – Diamonte Jan 27 '16 at 12:35