I'm learning Symfony 2 and am currently using Assetic to manage my CSS and Javascript files, like so:

{% stylesheets '@testMainBundle/Resources/public/css/*' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}" type="text/css" />
{% endstylesheets %}

{% javascripts '@testMainBundle/Resources/public/js/*' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

In @testMainBundle/Resources/public/js I have 3 files: bootstrap.min.js, jquery-1.10.2.min.js and main.js. However, the source code of the webpage comes out as:

<script type="text/javascript" src="/app_dev.php/js/4a0d3cd_part_1_bootstrap.min_1.js"></script>

Clearly, Assetic is only serving one file from that directory, the bootstrap file. I've checked and it's not combining the files, it's only the bootstrap.min.js file that's being output.

Assetic is working fine with two CSS files, however. I've tried refreshing my browser cache however nothing changes.

Also, as a side question, how do I make sure that Assetic outputs jquery-1.10.2.min.js before bootstrap.min.js? Bootstrap relies on jQuery so can't be printed first.

有帮助吗?

解决方案

Found my own solution, I had to do the following:

{% javascripts
    '@testMainBundle/Resources/public/js/jquery-1.10.2.min.js'
    '@testMainBundle/Resources/public/js/*' %}
    <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

Not sure if Assetic is documented to work this way however it seems to print out the jQuery include first and then every other file now. Perfect!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top