|
4 | 4 | How to Use Assetic for Asset Management
|
5 | 5 | =======================================
|
6 | 6 |
|
| 7 | +Installing and Enabling Assetic |
| 8 | +------------------------------- |
| 9 | + |
| 10 | +Starting from Symfony 2.8, Assetic is no longer included by default in the |
| 11 | +Symfony Standard Edition. Before using any of its features, install the |
| 12 | +AsseticBundle executing this console command in your project: |
| 13 | + |
| 14 | + .. code-block:: bash |
| 15 | +
|
| 16 | + $ composer require symfony/assetic-bundle |
| 17 | +
|
| 18 | +Then, enable the bundle in the ``AppKernel.php`` file of your Symfony application:: |
| 19 | + |
| 20 | + // app/AppKernel.php |
| 21 | + |
| 22 | + // ... |
| 23 | + class AppKernel extends Kernel |
| 24 | + { |
| 25 | + // ... |
| 26 | + |
| 27 | + public function registerBundles() |
| 28 | + { |
| 29 | + $bundles = array( |
| 30 | + // ... |
| 31 | + new Symfony\Bundle\AsseticBundle\AsseticBundle(), |
| 32 | + ); |
| 33 | + |
| 34 | + // ... |
| 35 | + } |
| 36 | + } |
| 37 | + |
| 38 | +Finally, add the following minimal configuration to enable Assetic support in |
| 39 | +your application: |
| 40 | + |
| 41 | +.. configuration-block:: |
| 42 | + |
| 43 | + .. code-block:: yaml |
| 44 | +
|
| 45 | + # app/config/config.yml |
| 46 | + assetic: |
| 47 | + debug: '%kernel.debug%' |
| 48 | + use_controller: '%kernel.debug%' |
| 49 | + filters: |
| 50 | + cssrewrite: ~ |
| 51 | +
|
| 52 | + # ... |
| 53 | +
|
| 54 | + .. code-block:: xml |
| 55 | +
|
| 56 | + <!-- app/config/config.xml --> |
| 57 | + <?xml version="1.0" encoding="UTF-8" ?> |
| 58 | + <container xmlns="http://symfony.com/schema/dic/services" |
| 59 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 60 | + xmlns:assetic="http://symfony.com/schema/dic/assetic" |
| 61 | + xsi:schemaLocation="http://symfony.com/schema/dic/services |
| 62 | + http://symfony.com/schema/dic/services/services-1.0.xsd |
| 63 | + http://symfony.com/schema/dic/assetic |
| 64 | + http://symfony.com/schema/dic/assetic/assetic-1.0.xsd"> |
| 65 | +
|
| 66 | + <assetic:config debug="%kernel.debug%" use-controller="%kernel.debug%"> |
| 67 | + <assetic:filters cssrewrite="null" /> |
| 68 | + </assetic:config> |
| 69 | +
|
| 70 | + <!-- ... --> |
| 71 | + </container> |
| 72 | +
|
| 73 | + .. code-block:: php |
| 74 | +
|
| 75 | + // app/config/config.php |
| 76 | + $container->loadFromExtension('assetic', array( |
| 77 | + 'debug' => '%kernel.debug%', |
| 78 | + 'use_controller' => '%kernel.debug%', |
| 79 | + 'filters' => array( |
| 80 | + 'cssrewrite' => null, |
| 81 | + ), |
| 82 | + // ... |
| 83 | + )); |
| 84 | +
|
| 85 | + // ... |
| 86 | +
|
| 87 | +Introducing Assetic |
| 88 | +------------------- |
| 89 | + |
7 | 90 | Assetic combines two major ideas: :ref:`assets <cookbook-assetic-assets>` and
|
8 | 91 | :ref:`filters <cookbook-assetic-filters>`. The assets are files such as CSS,
|
9 | 92 | JavaScript and image files. The filters are things that can be applied to
|
|
0 commit comments