Skip to content

[Framework] Add tag assets.package #14313

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions reference/dic_tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ application there could be more tags available provided by third-party bundles:
Tag Name Usage
======================================== ========================================================================
`auto_alias`_ Define aliases based on the value of container parameters
`assets.package`_ Add an asset package
`console.command`_ Add a command
`container.hot_path`_ Add to list of always needed services
`container.no_preload`_ Remove a class from the list of classes preloaded by PHP
Expand Down Expand Up @@ -50,6 +51,57 @@ Tag Name Usage
`validator.initializer`_ Register a service that initializes objects before validation
======================================== ========================================================================

assets.package
--------------

**Purpose**: Add an asset package to the application

This is an alternative way to declare a package in :doc:`/components/asset`.

The name of the package is set in this order:
* first, the `package` attribute of the tag
* then, the value returned by the static method `getDefaultName()` if defined
* finally, the service name

.. configuration-block::

.. code-block:: yaml

services:
App\Assets\AvatarPackage:
tags:
- { name: assets.package, package: avatars }

.. code-block:: xml

<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services
https://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="App\Assets\AvatarPackage">
<tag name="assets.package" package="avatars"/>
</service>
</services>
</container>

.. code-block:: php

use App\Assets\AvatarPackage;

$container
->register(AvatarPackage::class)
->addTag('assets.package', ['package' => 'avatars'])
;

Now you can use the ``avatars`` package in your templates:

.. code-block:: html+twig

<img src="{{ asset('...', 'avatars') }}">

auto_alias
----------

Expand Down