Important
This extension is no longer maintained.
TwigInflect is a Twig extension to transform the inflection of strings.
The extension adds the following filters:
- pluralize
- singularize
- camelize
- dasherize
- humanize
- hyphenate
- ordinalize
- pascalize
- titleize
- underscore
{
"require": {
"joshuabaker/twig-inflect": "dev-master"
}
}
<?php
use JoshuaBaker\Twig\Extensions\Extension\Inflect as TwigInflect;
$loader = new Twig_Loader_Filesystem('/path/to/templates');
$twig = new Twig_Environment($loader);
// Registers extension
$twig->setExtensions(new TwigInflect);
{{ 'car' | pluralize }}
{{ 'car' | pluralize(3) }}
{# cars #}
{{ 'bikes' | pluralize(1) }}
{{ 'bikes' | singularize }}
{# bike #}