Giter Site home page Giter Site logo

nochso / html-compress-twig Goto Github PK

View Code? Open in Web Editor NEW
81.0 5.0 17.0 22 KB

Twig extension for compressing HTML and inline CSS/JS using WyriHaximus/HtmlCompress

License: Other

PHP 100.00%
twig twig-extension compression minify minifier composer

html-compress-twig's Introduction

nochso/html-compress-twig extension

Latest Stable Version License Build Status

A Twig extension for 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

  1. Install and use composer in your project.

  2. Require this package via composer:

    composer require nochso/html-compress-twig

Usage

First register the extension with Twig:

$twig = new Twig_Environment($loader);
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension());

Then use it in your templates:

{% htmlcompress %}{% endhtmlcompress %}
{{ htmlcompress('<ul> <li>') }}
{{ '<ul> <li>'|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.

// Enable compression regardless of Twig's debug setting
$twig->addExtension(new \nochso\HtmlCompressTwig\Extension(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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.