shadesoft / twig-glob
此包已被弃用,不再维护。没有建议的替代包。
PHP 的 glob 函数的 Twig 扩展。
v1.1
2020-02-04 23:02 UTC
Requires
- twig/twig: ^2|^3
This package is auto-updated.
Last update: 2023-10-02 20:19:59 UTC
README
PHP 的 glob 函数的 Twig 扩展。
安装
打开命令行控制台,进入您的项目目录,并执行以下命令以下载此扩展的最新稳定版本
$ composer require shadesoft/twig-glob
此命令要求您已全局安装 Composer,如 Composer 文档中的安装章节所述。
将包包含到 Symfony 3-4 容器中(如果 autowire 和 autoconfigure 设置为 true)
# app/config/services.yml for Symfony 3 or config/services.yaml for Symfony 4 ShadeSoft\Twig\GlobExtension: ~
将包包含到 Symfony 2 容器中
# app/config/services.yml shadesoft.twig.glob_extension: class: ShadeSoft\Twig\GlobExtension tags: - { name: twig.extension }
将包包含到 Slim 框架的 Twig 视图渲染器中
// src/dependencies.php // ... $container['view'] = function($c) { //... $view->addExtension(new ShadeSoft\Twig\GlobExtension); //... }
用法
将 \ShadeSoft\Twig\GlobExtension 添加到您的 Twig 环境的依赖项中(或包含到上述框架之一中),然后您可以使用过滤器
{# 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 %}