Skip to content

Commit 3c18748

Browse files
committed
Add tag assets.package
1 parent ade35d4 commit 3c18748

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

reference/dic_tags.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ application there could be more tags available provided by third-party bundles:
1212
Tag Name Usage
1313
======================================== ========================================================================
1414
`auto_alias`_ Define aliases based on the value of container parameters
15+
`assets.package`_ Add an asset package
1516
`console.command`_ Add a command
1617
`container.hot_path`_ Add to list of always needed services
1718
`container.no_preload`_ Remove a class from the list of classes preloaded by PHP
@@ -50,6 +51,53 @@ Tag Name Usage
5051
`validator.initializer`_ Register a service that initializes objects before validation
5152
======================================== ========================================================================
5253

54+
assets.package
55+
--------------
56+
57+
**Purpose**: Add an asset package to the application
58+
59+
This is an alternative way to declare a package in :doc:`/components/asset`.
60+
The `package` attribute of the tag is required to name the package.
61+
62+
.. configuration-block::
63+
64+
.. code-block:: yaml
65+
66+
services:
67+
App\Assets\AvatarPackage:
68+
tags:
69+
- { name: assets.package, package: avatar }
70+
71+
.. code-block:: xml
72+
73+
<?xml version="1.0" encoding="UTF-8" ?>
74+
<container xmlns="http://symfony.com/schema/dic/services"
75+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
76+
xsi:schemaLocation="http://symfony.com/schema/dic/services
77+
https://symfony.com/schema/dic/services/services-1.0.xsd">
78+
79+
<services>
80+
<service id="App\Assets\AvatarPackage">
81+
<tag name="assets.package" package="avatar"/>
82+
</service>
83+
</services>
84+
</container>
85+
86+
.. code-block:: php
87+
88+
use App\Assets\AvatarPackage;
89+
90+
$container
91+
->register(AvatarPackage::class)
92+
->addTag('assets.package', ['package' => 'avatar'])
93+
;
94+
95+
Now you can use the ``avatars`` package in your templates:
96+
97+
.. code-block:: html+twig
98+
99+
<img src="{{ asset('...', 'avatars') }}">
100+
53101
auto_alias
54102
----------
55103

0 commit comments

Comments
 (0)