The AssetServiceProvider provides a way to manage URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files.
version
,
version_format
, base_urls
, and base_path
).1 2 3 4 5 6 7 8 | $app->register(new Silex\Provider\AssetServiceProvider(), array(
'assets.version' => 'v1',
'assets.version_format' => '%s?version=%s',
'assets.named_packages' => array(
'css' => array('version' => 'css2', 'base_path' => '/whatever-makes-sense'),
'images' => array('base_urls' => array('https://img.example.com')),
),
));
|
Note
Add the Symfony Asset Component as a dependency:
1 | composer require symfony/asset
|
If you want to use assets in your Twig templates, you must also install the Symfony Twig Bridge:
1 | composer require symfony/twig-bridge
|
The AssetServiceProvider is mostly useful with the Twig provider:
1 2 3 4 5 | {{ asset('/css/foo.png') }}
{{ asset('/css/foo.css', 'css') }}
{{ asset('/img/foo.png', 'images') }}
{{ asset_version('/css/foo.png') }}
|
For more information, check out the Asset Component documentation.