rdrenth / twig-extension-bundle
Symfony bundle with useful twig extensions
Installs: 3 823
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^5.3.3|^7.0
- danielstjules/stringy: ^2.3
- symfony/framework-bundle: ~2.3|~3.0
- twig/twig: ~1.20|~2.0
Requires (Dev)
- phpunit/phpunit: ^4.8
This package is not auto-updated.
Last update: 2024-11-06 23:27:11 UTC
README
About
This is a Symfony2 Bundle that provides you with some extensions to Twig!
Twig extensions
Stringy
This extension provides the following filters (provided by the Stringy package).
For more information about each filter, please check the links.
ascii
{{ 'fòôbàř'|ascii }} {# foobar #}
camelize
{{ 'Camel-Case'|camelize }} {# camelCase #}
dasherize
{{ 'fooBar'|dasherize }} {# foo-bar #}
delimit
{{ 'fooBar'|delimit('::') }} {# foo::bar #}
humanize
{{ 'author_id'|humanize }} {# Author #}
slugify
{{ 'Using strings like fòô bàř'| slugify }} {# using-strings-like-foo-bar #}
titleize
{{ 'i like to watch television'|titleize(['to']) }} {# I Like to Watch Television #}
underscored
{{ 'TestUCase'|underscored }} {# test_u_case #}
lcfirst
{{ 'LowerCaseFirst'|lcfirst }} {# lowerCaseFirst #}
ucfirst
{{ 'upperCaseFirst'|ucfirst }} {# UpperCaseFirst #}
Installation
Step 1: Install RdrenthTwigExtensionBundle using Composer
$ composer require rdrenth/twig-extension-bundle
Step 2: Enable the bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Rdrenth\Bundle\TwigExtensionBundle\RdrenthTwigExtensionBundle(), // ... ); }
Step 3: Configure your config.yml
file
By default the filters are disabled, enable the filters you want to use like this:
# app/config/config.yml rdrenth_twig_extension: stringy: filters: ascii: ~ camelize: ~
It is also possible to modify the filter name that is being used in Twig:
# app/config/config.yml rdrenth_twig_extension: stringy: filters: camelize: filter: camels
Or provide extra filters which are not available by default from the Stringy package (the method has to exist in the Stringy class):
# app/config/config.yml rdrenth_twig_extension: stringy: extra_filters: - { filter: swap_case, method: swapCase }
License
This bundle is under the MIT license. See the complete license in the bundle:
Resources/meta/LICENSE