Skip to content

Twig filters that format output of units of information by using ByteUnits library

License

Notifications You must be signed in to change notification settings

MarioBlazek/twig-byte-units-extension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Byte Units Twig extension

Build Status Code Coverage Downloads Latest stable License

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 by ByteUnits\Metric::format method
  • 1322000|byte_units_format_binary('MB') - Returns value formated in MiB as returned by ByteUnits\Binary::format method
  • 1322000|byte_units_bytes_metric - Returns the number of bytes as string returned by ByteUnits\Metric::numberOfBytes method
  • 1322000|byte_units_bytes_binary - Returns the number of bytes as string returned by ByteUnits\Binary::numberOfBytes method

for more information please check formating section on byte-units repo.

About

Twig filters that format output of units of information by using ByteUnits library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages