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