https://github.com/nochso/html-compress-twig
Twig extension for compressing HTML and inline CSS/JS using WyriHaximus/HtmlCompress
https://github.com/nochso/html-compress-twig
composer compression minifier minify twig twig-extension
Last synced: 5 months ago
JSON representation
Twig extension for compressing HTML and inline CSS/JS using WyriHaximus/HtmlCompress
- Host: GitHub
- URL: https://github.com/nochso/html-compress-twig
- Owner: nochso
- License: other
- Created: 2015-10-05T18:45:20.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2020-02-08T21:55:17.000Z (about 5 years ago)
- Last Synced: 2024-05-14T07:01:20.985Z (12 months ago)
- Topics: composer, compression, minifier, minify, twig, twig-extension
- Language: PHP
- Size: 21.5 KB
- Stars: 80
- Watchers: 5
- Forks: 17
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# nochso/html-compress-twig extension
[](https://packagist.org/packages/nochso/html-compress-twig)
[](LICENSE)
[](https://travis-ci.org/nochso/html-compress-twig)A [Twig](http://twig.sensiolabs.org/) extension for [WyriHaximus/HtmlCompress](https://github.com/WyriHaximus/HtmlCompress).
Currently supported Twig features are:
* Tag
* `{% htmlcompress %} ... {% endhtmlcompress %}`
* Function
* `{{ htmlcompress('some html') }}`
* Filter
* `{{ content|markdown|htmlcompress }}`Any HTML, inline CSS and Javascript will be compressed.
* [Installation](#installation)
* [Usage](#usage)
* [History](#history)
* [License](#license)## Installation
1. Install and use [composer](https://getcomposer.org/doc/00-intro.md) in your project.
2. Require this package via composer:```sh
composer require nochso/html-compress-twig
```## Usage
First register the extension with Twig:
```php
$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());
```Then use it in your templates:
```
{% htmlcompress %}{% endhtmlcompress %}
{{ htmlcompress('
- ') }}
{{ '- '|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 parameter `$forceCompression`. When true, this will force compression
regardless of Twig's `debug` setting. It defaults to false when omitted.```php
// Enable compression regardless of Twig's debug setting
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension(true));
```## History
See [CHANGELOG](CHANGELOG.md) 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](LICENSE) file for the full license text.
- '|htmlcompress }}