How to use assets filter to specific file in symfony

We can use assets filter to multiple or one file, there are given below different examples to understand the theory of assetic filter in symfony.

Follow this simple procedure by first activate it
If we want to use coffee script the following setting would happen:
 
# app/config/config.yml
assetic:
filters:
coffee:
bin: /usr/bin/coffee
node: /usr/bin/node
node_paths: [ /usr/lib/node_modules/ ]

Now if we are using single filter the following settings would be followed by:

{% javascripts ‘@YourFooBundle/Resources/public/js/example.coffee’ filter=’coffee’ %}
<script src=”{{ asset_url }}” type=”text/javascript”></script>
{% endjavascripts %}

Happy coding to single filter

Now if we want to use multiple filters
{% javascripts ‘@YourFooBundle/Resources/public/js/one.coffee’
‘@YourFooBundle/Resources/public/js/second.coffee’
filter=’coffee’ %}
<script src=”{{ asset_url }}” type=”text/javascript”></script>
{% endjavascripts %}

Happy coding to filter for multiple files

One very fast and interesting thing which symfony also provides is an file base extention like :

Use this configuration :

# app/config/config.yml
assetic:
filters:
coffee:
bin: /usr/bin/coffee
node: /usr/bin/node
node_paths: [ /usr/lib/node_modules/ ]
apply_to: “\.coffee$”

That above would avoid us from referencing again and again same filter.

Now go to your coding and use the following syntax:

{% javascripts ”@YourFooBundle/Resources/public/js/my.js’
‘@YourFooBundle/Resources/public/js/second.coffee’
 @YourFooBundle/Resources/public/js/first.coffee’%}
<script src=”{{ asset_url }}” type=”text/javascript”></script>
{% endjavascripts %}