sanhpotter/html-compress-twig
Composer 安装命令:
composer require sanhpotter/html-compress-twig
包简介
Twig extension for compressing HTML
README 文档
README
Description
A Twig extension for voku/HtmlMin.
Currently supported Twig features are:
-
Tag
{% htmlcompress %} <foo>bar</foo> {% endhtmlcompress %}
-
Function
{{ htmlcompress(' <foo>bar</foo>') }}
-
Filter
{{ ' <foo>bar</foo>' | htmlcompress }}
Installation
- Install and use composer in your project.
- Require this package via composer:
composer require sn/html-compress-twig
Usage
First register the extension with Twig:
use voku\helper\HtmlMin; use sn\twig\MinifyHtmlExtension; $twig = new \Twig\Environment($loader); $minifier = new HtmlMin(); $twig->addExtension(new MinifyHtmlExtension($minifier));
Register extension in symfony 4
Specifying HtmlMin is needed for the autowiring.
voku\helper\HtmlMin: tags: - { name: HtmlMin } sn\twig\MinifyHtmlExtension: arguments: $forceCompression: false tags: - { name: twig.extension }
Then use it in your templates:
{% htmlcompress %} <foo>bar</foo> {% endhtmlcompress %}
{{ htmlcompress(' <foo>bar</foo>') }}
{{ ' <foo>bar</foo>' | htmlcompress }}
Compression is disabled by Twig's debug setting. This is to make development easier, however you can always
override it.
The constructor of this extension takes a boolean as second parameter $forceCompression. When true, this will
force compression regardless of Twig's debug setting. It defaults to false when omitted.
$twig->addExtension(new MinifyHtmlExtension($minifier, true));
History
See CHANGELOG for the full history of changes.
License
This project is licensed under the ISC license which is MIT/GPL compatible and FSF/OSI approved. See the LICENSE file for the full license text.
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: ISC
- 更新时间: 2023-07-13