@@ -16,6 +16,20 @@ the AsseticBundle has several tags that aren't listed here.
16
16
+-----------------------------------+---------------------------------------------------------------------------+
17
17
| Tag Name | Usage |
18
18
+-----------------------------------+---------------------------------------------------------------------------+
19
+ | `assetic.asset `_ | Register an asset to the current asset manager |
20
+ +-----------------------------------+---------------------------------------------------------------------------+
21
+ | `assetic.factory_worker `_ | Add a factory worker |
22
+ +-----------------------------------+---------------------------------------------------------------------------+
23
+ | `assetic.filter `_ | Register a filter |
24
+ +-----------------------------------+---------------------------------------------------------------------------+
25
+ | `assetic.formula_loader `_ | Add a formula loader to the current asset manager |
26
+ +-----------------------------------+---------------------------------------------------------------------------+
27
+ | `assetic.formula_resource `_ | Adds a resource to the current asset manager |
28
+ +-----------------------------------+---------------------------------------------------------------------------+
29
+ | `assetic.templating.php `_ | Remove this service if php templating is disabled |
30
+ +-----------------------------------+---------------------------------------------------------------------------+
31
+ | `assetic.templating.twig `_ | Remove this service if twig templating is disabled |
32
+ +-----------------------------------+---------------------------------------------------------------------------+
19
33
| `data_collector `_ | Create a class that collects custom data for the profiler |
20
34
+-----------------------------------+---------------------------------------------------------------------------+
21
35
| `form.type `_ | Create a custom form field type |
@@ -53,6 +67,163 @@ the AsseticBundle has several tags that aren't listed here.
53
67
| `validator.initializer `_ | Register a service that initializes objects before validation |
54
68
+-----------------------------------+---------------------------------------------------------------------------+
55
69
70
+ assetic.asset
71
+ -------------
72
+
73
+ **Purpose **: Register an asset to the current asset manager
74
+
75
+ assetic.factory_worker
76
+ ----------------------
77
+
78
+ **Purpose **: Add a factory worker
79
+
80
+ Factory worker is a class implementing
81
+ ``Assetic\\Factory\\Worker\\WorkerInterface ``. Its ``process($asset) ``
82
+ method is called for each asset after asset creation. You can modify an asset or
83
+ even return a new one.
84
+
85
+ In order to add a new worker, first create a class::
86
+
87
+ use Assetic\Asset\AssetInterface;
88
+ use Assetic\Factory\Worker\WorkerInterface;
89
+
90
+ class MyWorker implements WorkerInterface
91
+ {
92
+ public function process(AssetInterface $asset)
93
+ {
94
+ // ... change $asset or return a new one
95
+ }
96
+
97
+ }
98
+
99
+ And then add register it as a tagged service:
100
+
101
+ .. configuration-block ::
102
+
103
+ .. code-block :: yaml
104
+
105
+ services :
106
+ acme.my_worker :
107
+ class : MyWorker
108
+ tags :
109
+ - { name: assetic.factory_worker }
110
+
111
+ .. code-block :: xml
112
+
113
+ <service id =" acme.my_worker" class =" MyWorker>
114
+ <tag name=" assetic.factory_worker" />
115
+ </service>
116
+
117
+ .. code-block:: php
118
+
119
+ $container
120
+ ->register('acme.my_worker', 'MyWorker')
121
+ ->addTag('assetic.factory_worker')
122
+ ;
123
+
124
+ assetic.filter
125
+ --------------
126
+
127
+ **Purpose**: Register a filter
128
+
129
+ AsseticBundle uses this filter to register common filters. You can also use this
130
+ tag to register your own filters.
131
+
132
+ First, you need to create a filter::
133
+
134
+ use Assetic\Asset\AssetInterface;
135
+ use Assetic\Filter\FilterInterface;
136
+
137
+ class MyFilter implements FilterInterface
138
+ {
139
+ public function filterLoad(AssetInterface $asset)
140
+ {
141
+ $asset->setContent('alert(" yo" );' . $asset->getContent());
142
+ }
143
+
144
+ public function filterDump(AssetInterface $asset)
145
+ {
146
+ // ...
147
+ }
148
+ }
149
+
150
+ Second, define a service:
151
+
152
+ .. configuration-block::
153
+
154
+ .. code-block:: yaml
155
+
156
+ services:
157
+ acme.my_filter:
158
+ class: MyFilter
159
+ tags:
160
+ - { name: assetic.filter, alias: my_filter }
161
+
162
+ .. code-block:: xml
163
+
164
+ <service id=" acme.my_filter" class=" MyFilter" >
165
+ <tag name=" assetic.filter" alias=" my_filter" />
166
+ </service>
167
+
168
+ .. code-block:: php
169
+
170
+ $container
171
+ ->register('acme.my_filter', 'MyFilter')
172
+ ->addTag('assetic.filter', array('alias' => 'my_filter'))
173
+ ;
174
+
175
+ Finally, apply the filter:
176
+
177
+ .. code-block:: jinja
178
+
179
+ {% javascripts
180
+ '@AcmeBaseBundle/Resources/public/js/global.js'
181
+ filter='my_filter'
182
+ %}
183
+ <script src=" {{ asset_url }}" ></script>
184
+ {% endjavascripts %}
185
+
186
+ You can also apply your filter via ``assetic.filters.my_filter.apply_to`` config
187
+ option as it's described here: :doc:`/cookbook/assetic/apply_to_option`. In
188
+ order to do that, you must define your filter service in separate xml config
189
+ file and put this file's path to ``assetic.filters.my_filter.resource``.
190
+
191
+ assetic.formula_loader
192
+ ----------------------
193
+
194
+ **Purpose**: Add a formula loader to the current asset manager
195
+
196
+ Formula loader is a class implementing
197
+ ``Assetic\\Factory\Loader\\FormulaLoaderInterface`` interface. This class
198
+ is responsible in loading assets from a particular kind of resources (for
199
+ instance, twig template). Assetic ships loaders for php and twig templates.
200
+
201
+ An ``alias`` attribute defines a name of the loader.
202
+
203
+ assetic.formula_resource
204
+ ------------------------
205
+
206
+ **Purpose**: Adds a resource to the current asset manager
207
+
208
+ A resource is something formulae can be loaded from. For instance, twig
209
+ templates are resources.
210
+
211
+ assetic.templating.php
212
+ ----------------------
213
+
214
+ **Purpose**: Remove this service if php templating is disabled
215
+
216
+ The tagged service will be removed from the container if
217
+ ``framework.templating.engines`` config section does not contain php.
218
+
219
+ assetic.templating.twig
220
+ ----------------------
221
+
222
+ **Purpose**: Remove this service if twig templating is disabled
223
+
224
+ The tagged service will be removed from the container if
225
+ ``framework.templating.engines`` config section does not contain twig.
226
+
56
227
data_collector
57
228
--------------
58
229
0 commit comments