https://github.com/rauwebieten/twig-humanizer-extension
A twig extension for the coduo/php-humanizer library
https://github.com/rauwebieten/twig-humanizer-extension
humanizer php twig twig-extension
Last synced: 5 months ago
JSON representation
A twig extension for the coduo/php-humanizer library
- Host: GitHub
- URL: https://github.com/rauwebieten/twig-humanizer-extension
- Owner: rauwebieten
- License: lgpl-3.0
- Created: 2019-01-15T16:54:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-23T08:59:14.000Z (over 7 years ago)
- Last Synced: 2025-11-18T04:14:21.532Z (7 months ago)
- Topics: humanizer, php, twig, twig-extension
- Language: PHP
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Twig Humanizer Extension
[](https://travis-ci.org/rauwebieten/twig-humanizer-extension)
[](https://codeclimate.com/github/rauwebieten/twig-humanizer-extension/maintainability)
[](https://codecov.io/gh/rauwebieten/twig-humanizer-extension)
[](https://github.styleci.io/repos/165889067)


A [Twig extension](https://github.com/twigphp/Twig)
for the [PHP Humanizer library](https://github.com/coduo/php-humanizer)
Use the humanizer functions from the coduo/php-humanizer library in your Twig templates.
## Installation
```
composer require rauwebieten/twig-humanizer-extension
```
## Available filters
All filters are underscored, and prefixed:
- humanizer_humanize
- humanizer_truncate
- humanizer_truncate_html
- humanizer_ordinalize
- humanizer_ordinal
- humanizer_to_roman
- humanizer_from_roman
- humanizer_binary_suffix
- humanizer_precise_binary_suffix
- humanizer_metric_suffix
- humanizer_metric_suffix
- humanizer_oxford
- humanizer_difference
- humanizer_precise_difference
See the [PHP Humanizer documentation](https://github.com/coduo/php-humanizer) for details.
## Example usage
```twig,html
1 to 12 in roman:
{% for i in 1..12 %}
{{ i|humanizer_to_roman }}
{% endfor %}
Roman VI = {{ 'VI'|humanizer_from_roman }}
1024 bytes = {{ 1024|humanizer_binary_suffix }}
1024 bytes = {{ 1024|humanizer_precise_binary_suffix(2) }}
This article was posted
{{ date("now")|humanizer_difference(date("2014-04-24")) }}
{{ ['Michal', 'Norbert', 'Lukasz', 'Pawel']|humanizer_oxford(2) }}
1240 metric = {{ 1240|humanizer_metric_suffix }}
first: 1{{ 1|humanizer_ordinal }}
first: {{ 1|humanizer_ordinalize }}
{{ 'Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc.'|humanizer_truncate(8,'...') }}
{{ 'HyperText Markup Language, commonly referred to as HTML
'|humanizer_truncate_html(3)|raw }}
{{ 'HyperText Markup Language, commonly referred to as HTML
'|humanizer_truncate_html(3,'')|raw }}
```