jmf / twig-extensions-bundle
Collection of Twig extensions as a Symfony Bundle
Installs: 20
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^8.0
- jmf/twig-array: ^1.0
- jmf/twig-currency: ^1.0
- jmf/twig-inline: ^1.0
- jmf/twig-sort: ^1.0
- jmf/twig-time: ^1.0
- jmf/twig-type: ^1.0
- symfony/framework-bundle: ^7.0
Requires (Dev)
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^3.8
README
Collection of Twig extensions as a Symfony Bundle, which provides:
- array operations;
- set/unset a specific array key (
array_set
,array_unset
) - add a value to front/back of array (
array_push
,array_unshift
) - remove a value from front/back of array (
array_pop
,array_shift
)
- set/unset a specific array key (
- currency operations:
- format a money amount (
amount|money_amount
)
- format a money amount (
- inlining operations:
- dump the raw content of a file (
inline('style.css')
)
- dump the raw content of a file (
- sorting operations:
- sort arrays by value (
sort
,rsort
) - sort arrays by value, keeping associativity (
asort
,arsort
) - sort arrays by key (
ksort
,krsort
) - sort arrays by properties (
psort
)
- sort arrays by value (
- time-related operations:
- adds direct access to PHP microtime() function
- adds direct access to PHP intl_format() function
- type-related operations:
- adds direct access to PHP get_class() and gettype() functions
- adds support to identify a Twig variable type with new tests (
is array
,is string
, etc)
Installation & Requirements
Install with Composer:
composer require jmf/twig-extensions-bundle
If you have Flex installed, the Twig extensions are then instantly available without any need for initial configuration.
If not, complete your config/bundles.php
file as indicated below:
<?php return [ // ... // Other existing bundles. // ... Jmf\TwigExtensionsBundle\JmfTwigExtensionsBundle::class => ['all' => true], ];
Configuration (optional)
Either run the following command:
bin/console config:dump jmf_twig_extensions > config/packages/jmf_twig_extensions.yaml
Or create a jmf_twig_extensions.yaml
file in the config/package
directory as follows:
jmf_twig_extensions: # Twig "array" extension configuration. array: enabled: true # Optional prefix before function and filter names. prefix: '' # Twig "currency" extension configuration. currency: enabled: true # Optional prefix before function and filter names. prefix: '' # Twig "inline" extension configuration. inline: # Base path to restrict file inlining. Also, all calls to the "inline" function will be relative to this path. basePath: '%kernel.project_dir%/templates' enabled: true # Optional prefix before function and filter names. prefix: '' # Twig "sort" extension configuration. sort: enabled: true # Optional prefix before function and filter names. prefix: '' # Twig "time" extension configuration. time: enabled: true # Optional locale for date and time representation. locale: null # Optional prefix before function and filter names. prefix: '' # Twig "type" extension configuration. type: enabled: true # Optional prefix before function and filter names. prefix: ''
You may then alter any parameter to fit your needs.
Included Twig Extensions
Twig array extension
See https://packagist.org/packages/jmf/twig-array for documentation.
Twig currency extension
See https://packagist.org/packages/jmf/twig-currency for documentation.
Twig inline extension
See https://packagist.org/packages/jmf/twig-inline for documentation.
Twig sort extension
See https://packagist.org/packages/jmf/twig-sort for documentation.
Twig time extension
See https://packagist.org/packages/jmf/twig-time for documentation.
Twig type extension
See https://packagist.org/packages/jmf/twig-type for documentation.