Warm tip: This article is reproduced from stackoverflow.com, please click
php symfony twig

How can I get the assests version value in Symfony2 or Twig?

发布于 2020-03-27 10:17:00

I need to display in the footer of my app the assets version set in app/config.yml file:

framework:
templating:
    engines: ['twig']
    assets_version: v2.6.2

How can I get in Twig or in a controller the assets_version value?

Questioner
Sergiu
Viewed
127
Adrian C. 2015-10-02 00:00

You can use the AssetsExtension's getAssetsVersion method.

So, in a controller:

$this->container->get('templating.helper.assets')->getVersion();

Or in a Twig file:

{{ assets_version() }}

Check https://github.com/symfony/symfony/blob/2.3/src/Symfony/Bundle/TwigBundle/Extension/AssetsExtension.php