Rolintocour
Rolintocour

Reputation: 3148

Symfony2: asset version with assetic

I need to manage my javascripts files version, to avoid the user from using an out of date file.

I my config file, I defined :

assets_version: v2.1

It works well when I use:

<script type="text/javascript"
src="{{ asset('bundles/mybundle/js/my_js.js') }}"></script>

But if I also need to use the javascripts tags like:

{% javascripts
'bundles/my_bundle/js/js1.js'
'bundles/my_bundle/js/js2.js'
 %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

But then the version is not applied. Also tried:

<script type="text/javascript" src="{{ asset(asset_url) }}"></script>

But this duplicates the base path of the file. What is the good way to do it?

Upvotes: 1

Views: 786

Answers (1)

COil
COil

Reputation: 7586

When using:

{% javascripts
    'bundles/my_bundle/js/js1.js'
    'bundles/my_bundle/js/js2.js'
 %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}

You will need to use the production controller (app.php) (without debug) to see the asset version appended. (you have to dump your assets too)

<script type="text/javascript" src="http://assets2.yoursite.com/js/youjs.js?v2.1"></script>

In dev mode you probably have something like this:

<script type="text/javascript" src="/app_dev.php/js/js1.js"></script>
<script type="text/javascript" src="/app_dev.php/js/js2.js"></script>

Upvotes: 1

Related Questions