emodric/twig-package-versions

Twig functions that return a package version by using PackageVersions library by Marco Pivetta

1.0.1 2019-11-22 13:24 UTC

This package is auto-updated.

Last update: 2020-11-22 15:54:00 UTC


README

Build Status Code Coverage Downloads Latest stable License

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 by PackageVersions\Versions::getVersion method
  • pretty_package_version('my-vendor/package-name') - Returns the Jean85\Version object as returned by Jean85\PrettyVersions::getVersion method