Skip to content

adybionka/kohana-compress-for-twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Compress & Twig modules integration

Kohana module to integrate Kohana Compress module with Kohana Twig module.

Requirements

  • PHP 5.2+
  • Kohana PHP 3.3.x

Setup

  • Enable the compress module in Kohana's bootstrap file.

Configuration (config/compress_for_twig.php)

	'disabled_in_environments' => array(),

List of environment modes on which compress tag should be disabled. For instance if you want to disabled compress tag on DEVELOPMENT environment add Kohana::DEVELOPMENT into array.

Usage

Just wrap javascripts or stylesheets into {% compress %} template tag. You can use variables, filters and different template tags inside compress tag like: block, for, if etc. Compress template tag first render piece of html under {% compress %} and then find stylesheets or javascripts to compress them.

NOTE: if you put javascripts and stylesheets in common block, result will be only compressed stylesheet file. Javascripts files will be skipped. So please do not mix your stylesheets and javascripts files into one block.

JavaScript files compress into one file:

In your HTML template use template tag {% compress %}:

{% compress %}
  <script src="/bower_components/jquery/dist/jquery.js" type="text/javascript"></script>        
  <script src="/bower_components/history.js/scripts/bundled-uncompressed/html4+html5/jquery.history.js" type="text/javascript"></script>
  <script src="/bower_components/jquery-touchswipe/jquery.touchSwipe.js" type="text/javascript"></script>
  <script src="/js/app.js" type="text/javascript"></script>
{% endcompress %}

Result in rendered HTML will be:

<script type="text/javascript" src="/static/cache/b00433df1d20b42b150d0cef412baeba0e9e8375.js"></script>

Stylesheets files compress into one file:

In your HTML template use template tag {% compress %}:

{% compress %}
  <link href="/static/css/style.css" rel="stylesheet" type="text/css" />
  <link href="/bower_components/bootstrap/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
  <link href="/bower_components/normalize.css/normalize.css" rel="stylesheet" type="text/css" />
  <link href="/static/css/style.css" rel="stylesheet" type="text/css" />
{% endcompress %}

Result in rendered HTML will be:

<link type="text/css" href="/static/cache/092dafa16671cc9768cb21ec7fb74b3f8fa14153.css" rel="stylesheet" />

Links

Kohana Twig

Kohana Compress

Kohana PHP Framework

Twig

About

Kohana module to integrate Compress module with Twig module

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages