cviebrock / twig-natural-join
Twig filter that joins an array using a different separator for the last element
Installs: 5 043
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=5.3.0
- twig/twig: 1.*
This package is auto-updated.
Last update: 2024-11-05 18:36:37 UTC
README
Twig filter that joins an array using a different separator for the last element (e.g. "John, Mary, Bob and Jim").
Installation
The filter is registered at Packagist as cviebrock/twig-natural-join and can be installed using composer:
"require": {
...
"cviebrock/twig-natural-join": "0.9.*",
}
Or just download the zip file and copy the file into your src folder.
Enable the extension:
$twig = new Twig_Environment($loader, $options); $twig->addExtension(new Cviebrock\Twig\NaturalJoinExtension());
If you are using Laravel and rcrowe/twigbridge, then enable the extension by adding an entry to the enabled
array in app/config/packages/rcrowe/twigbridge/extensions.php
:
'enabled' => [ ... 'Cviebrock\Twig\NaturalJoinExtension', ],
Usage
Pass the normal seperator and final seperator to the filter:
{{ names|naturaljoin(", ", " and ") }} // John, Bill, Bob and Mary
Optionally pass true
as a third argument to turn on "Oxford" mode, which will add a normal seperator before the final seperator:
{{ names|naturaljoin(", ", " and ", true) }} // John, Bill, Bob, and Mary
Bugs, Suggestions and Contributions
Please use Github for bugs, comments, suggestions.
- Fork the project.
- Create your bugfix/feature branch and write your (well-commented) code.
- Commit your changes and push to your repository.
- Create a new pull request against this project's
master
branch.
Copyright and License
twig-natural-join was written by Colin Viebrock and released under the MIT License. See the LICENSE file for details.
Copyright 2014 Colin Viebrock