shadesoft / twig-glob
Twig extension for usage of PHP's glob function.
Fund package maintenance!
Ko Fi
www.buymeacoffee.com/ShadeSoft
www.paypal.me/ShadeSoft
Installs: 100
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Type:package
Requires
- twig/twig: ^2|^3
This package is auto-updated.
Last update: 2023-10-02 20:19:59 UTC
README
Twig extension for usage of PHP's glob function.
Installation
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require shadesoft/twig-glob
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Including into Symfony 3-4 container (if autowire and autoconfigure is set to true)
# app/config/services.yml for Symfony 3 or config/services.yaml for Symfony 4 ShadeSoft\Twig\GlobExtension: ~
Including into Symfony 2 container
# app/config/services.yml shadesoft.twig.glob_extension: class: ShadeSoft\Twig\GlobExtension tags: - { name: twig.extension }
Including into Slim Framework's Twig view renderer
// src/dependencies.php // ... $container['view'] = function($c) { //... $view->addExtension(new ShadeSoft\Twig\GlobExtension); //... }
Usage
Add \ShadeSoft\Twig\GlobExtension to your Twig environment's dependencies (or include into one of the frameworks above), then you can use the filter:
{# Without parameters, the filter will return both the matched strings and the found resource as associative array, so you can use it like below: #} {% for size, icon in 'img/icons/favicon-*.png'|glob %} <link rel="icon" type="image/png" sizes="{{ size }}" href="{{ asset(icon) }}"> {% endfor %} {# With the optional returnMatch parameter set to false, you will get a simple array with the found resources, like below: #} {% for css in 'node_modules/@fortawesome/fontawesome-free-webfonts/css/*.css'|glob(false) %} <link href="{{ asset(css) }}" rel="stylesheet"> {% endfor %}