marioblazek / twig-byte-units-extension
Twig filters that format output of units of information by using ByteUnits library by Gabriele Lana
Installs: 15 185
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.1|^8.0
- gabrielelana/byte-units: ^0.5
- twig/twig: ^1.35.2 || ^2.4.6 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^7.1
This package is auto-updated.
Last update: 2024-12-23 15:29:38 UTC
README
This package provides simple Twig filters that wrap ByteUnits lib by Gabriele Lana which makes manipulation with informational units very easy.
Installation
To install this extension, use Composer:
composer require marioblazek/twig-byte-units-extension
Using the extension
In PHP:
$twig = new Twig_Environment($loader, $options); $twig->addExtension(new Marek\Twig\ByteUnitsExtension());
In a Symfony project, you can register the extension as a service:
services: twig.extension.byte_units: class: Marek\Twig\ByteUnitsExtension tags: - { name: twig.extension }
Once set up, you can use the following Twig filters:
1322000|byte_units_format_metric('MB')
- Returns value formated in MB as returned byByteUnits\Metric::format
method1322000|byte_units_format_binary('MB')
- Returns value formated in MiB as returned byByteUnits\Binary::format
method1322000|byte_units_bytes_metric
- Returns the number of bytes as string returned byByteUnits\Metric::numberOfBytes
method1322000|byte_units_bytes_binary
- Returns the number of bytes as string returned byByteUnits\Binary::numberOfBytes
method
for more information please check formating section on byte-units repo.