Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.2k
Add assetic DIC tags reference.#2480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -16,6 +16,20 @@ the AsseticBundle has several tags that aren't listed here. | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| Tag Name | Usage | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.asset`_ | Register an asset to the current asset manager | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.factory_worker`_ | Add a factory worker | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.filter`_ | Register a filter | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.formula_loader`_ | Add a formula loader to the current asset manager | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.formula_resource`_ | Adds a resource to the current asset manager | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.templating.php`_ | Remove this service if php templating is disabled | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `assetic.templating.twig`_ | Remove this service if twig templating is disabled | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `data_collector`_ | Create a class that collects custom data for the profiler | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
| `form.type`_ | Create a custom form field type | | ||
@@ -53,6 +67,163 @@ the AsseticBundle has several tags that aren't listed here. | ||
| `validator.initializer`_ | Register a service that initializes objects before validation | | ||
+-----------------------------------+---------------------------------------------------------------------------+ | ||
assetic.asset | ||
------------- | ||
**Purpose**: Register an asset to the current asset manager | ||
assetic.factory_worker | ||
---------------------- | ||
**Purpose**: Add a factory worker | ||
Factory worker is a class implementing | ||
``Assetic\\Factory\\Worker\\WorkerInterface``. Its ``process($asset)`` | ||
method is called for each asset after asset creation. You can modify an asset or | ||
even return a new one. | ||
In order to add a new worker, first create a class:: | ||
use Assetic\Asset\AssetInterface; | ||
use Assetic\Factory\Worker\WorkerInterface; | ||
class MyWorker implements WorkerInterface | ||
{ | ||
public function process(AssetInterface $asset) | ||
{ | ||
// ... change $asset or return a new one | ||
} | ||
} | ||
And then add register it as a tagged service: | ||
.. configuration-block:: | ||
.. code-block:: yaml | ||
services: | ||
acme.my_worker: | ||
class: MyWorker | ||
tags: | ||
- { name: assetic.factory_worker } | ||
.. code-block:: xml | ||
<service id="acme.my_worker" class="MyWorker> | ||
<tag name="assetic.factory_worker" /> | ||
</service> | ||
.. code-block:: php | ||
$container | ||
->register('acme.my_worker', 'MyWorker') | ||
->addTag('assetic.factory_worker') | ||
; | ||
assetic.filter | ||
-------------- | ||
**Purpose**: Register a filter | ||
AsseticBundle uses this filter to register common filters. You can also use this | ||
tag to register your own filters. | ||
First, you need to create a filter:: | ||
use Assetic\Asset\AssetInterface; | ||
use Assetic\Filter\FilterInterface; | ||
class MyFilter implements FilterInterface | ||
{ | ||
public function filterLoad(AssetInterface $asset) | ||
{ | ||
$asset->setContent('alert("yo");' . $asset->getContent()); | ||
} | ||
public function filterDump(AssetInterface $asset) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. do you really mean an empty function, or do you mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Usually filters do their job in one of these methods, while the second one is empty. Should I still add | ||
// ... | ||
} | ||
} | ||
Second, define a service: | ||
.. configuration-block:: | ||
.. code-block:: yaml | ||
services: | ||
acme.my_filter: | ||
class: MyFilter | ||
tags: | ||
- { name: assetic.filter, alias: my_filter } | ||
.. code-block:: xml | ||
<service id="acme.my_filter" class="MyFilter"> | ||
<tag name="assetic.filter" alias="my_filter" /> | ||
</service> | ||
.. code-block:: php | ||
$container | ||
->register('acme.my_filter', 'MyFilter') | ||
->addTag('assetic.filter', array('alias' => 'my_filter')) | ||
; | ||
Finally, apply the filter: | ||
.. code-block:: jinja | ||
{% javascripts | ||
'@AcmeBaseBundle/Resources/public/js/global.js' | ||
filter='my_filter' | ||
%} | ||
<script src="{{ asset_url }}"></script> | ||
{% endjavascripts %} | ||
You can also apply your filter via ``assetic.filters.my_filter.apply_to`` config | ||
option as it's described here: :doc:`/cookbook/assetic/apply_to_option`. In | ||
order to do that, you must define your filter service in separate xml config | ||
file and put this file's path to ``assetic.filters.my_filter.resource``. | ||
assetic.formula_loader | ||
---------------------- | ||
**Purpose**: Add a formula loader to the current asset manager | ||
Formula loader is a class implementing | ||
``Assetic\\Factory\Loader\\FormulaLoaderInterface`` interface. This class | ||
is responsible in loading assets from a particular kind of resources (for | ||
instance, twig template). Assetic ships loaders for php and twig templates. | ||
An ``alias`` attribute defines a name of the loader. | ||
assetic.formula_resource | ||
------------------------ | ||
**Purpose**: Adds a resource to the current asset manager | ||
A resource is something formulae can be loaded from. For instance, twig | ||
templates are resources. | ||
assetic.templating.php | ||
---------------------- | ||
**Purpose**: Remove this service if php templating is disabled | ||
The tagged service will be removed from the container if | ||
``framework.templating.engines`` config section does not contain php. | ||
assetic.templating.twig | ||
---------------------- | ||
**Purpose**: Remove this service if twig templating is disabled | ||
The tagged service will be removed from the container if | ||
``framework.templating.engines`` config section does not contain twig. | ||
data_collector | ||
-------------- | ||