emodric / twig-package-versions
Twig functions that return a package version by using jean85/pretty-package-versions library
Installs: 101 058
Dependents: 1
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/emodric/twig-package-versions
Requires
- jean85/pretty-package-versions: ^1.6 || ^2.0
- twig/twig: ^2.14 || ^3.2
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-10-05 22:32:17 UTC
README
This package provides simple Twig functions that wrap PackageVersions lib by Marco Pivetta and PrettyPackageVersions lib by Alessandro Lai making it possible to output version strings of your libraries directly inside your Twig templates.
Initially, this Twig extension was submitted as a pull request against official Twig Extensions collection, but was turned into a separate package since no new features are accepted over there.
Installation
To install this extension, use Composer:
composer require emodric/twig-package-versions
Using the extension
In PHP:
$twig = new \Twig\Environment($loader, $options); $twig->addExtension(new \EdiModric\Twig\VersionExtension());
In a Symfony project, you can register the extension as a service:
services: twig.extension.version: class: EdiModric\Twig\VersionExtension tags: - { name: twig.extension }
Once set up, you can use the following Twig functions:
package_version('my-vendor/package-name')- Returns the package version string as returned byPackageVersions\Versions::getVersionmethodpretty_package_version('my-vendor/package-name')- Returns theJean85\Versionobject as returned byJean85\PrettyVersions::getVersionmethod