定制 voku/html-compress-twig 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

voku/html-compress-twig

最新稳定版本:4.0.2

Composer 安装命令:

composer require voku/html-compress-twig

包简介

Twig extension for compressing HTML

README 文档

README

Build Status Coverage Status Scrutinizer Code Quality Codacy Badge SensioLabsInsight Latest Stable Version Total Downloads Latest Unstable Version License

🗜️ HtmlMin for Twig: HTML Compressor and Minifier

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

  • Usage

  • History

  • License

Installation

  1. Install and use composer in your project.
  2. Require this package via composer:
composer require voku/html-compress-twig

Usage

First register the extension with Twig:

use voku\helper\HtmlMin;
use voku\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 }

    voku\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.

统计信息

  • 总下载量: 2.14M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 28
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 25
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: ISC
  • 更新时间: 2017-03-18