PHPackages                             tommcdo/kohana-twig - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. tommcdo/kohana-twig

ActiveKohana-module[Templating &amp; Views](/categories/templating)

tommcdo/kohana-twig
===================

Kohana 3.3 module for the popular Twig template engine

1.0.1(11y ago)241.9k16[1 issues](https://github.com/tommcdo/kohana-twig/issues)[1 PRs](https://github.com/tommcdo/kohana-twig/pulls)MITPHPPHP &gt;=5.3.3

Since Sep 16Pushed 1y ago4 watchersCompare

[ Source](https://github.com/tommcdo/kohana-twig)[ Packagist](https://packagist.org/packages/tommcdo/kohana-twig)[ Docs](https://github.com/tommcdo/kohana-twig)[ RSS](/packages/tommcdo-kohana-twig/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (5)Versions (3)Used By (0)

kohana-twig Composer
====================

[](#kohana-twig-composer)

Version 1.0.1

[![Build Status](https://camo.githubusercontent.com/79cbe671563e27880c2d9b0b00e441b22e448c02f54258e875b7125e6b627f34/68747470733a2f2f7472617669732d63692e6f72672f746f6d6d63646f2f6b6f68616e612d747769672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/tommcdo/kohana-twig)

Kohana-twig is a [Kohana](http://kohanaframework.org) 3.3 module for the popular [Twig](http://twig.sensiolabs.org) template engine. It was designed to offer the full capabilities of Twig with a strong focus on operating within the guidelines and best practices of the Kohana framework. This module provides a way to use Twigs exactly as Kohana [Views](http://kohanaframework.org/3.3/guide/kohana/mvc/views)are used, and it uses a custom Twig Loader to locate Twig template files in the [Cascading Filesystem](http://kohanaframework.org/3.3/guide/kohana/files).

Looking for a Koseven module?
-----------------------------

[](#looking-for-a-koseven-module)

Take a look at [koseven-twig](https://github.com/errotan/koseven-twig) by [errotan](https://github.com/errotan).

Installation
------------

[](#installation)

First, add the package to your composer.json requirements:

```
"tommcdo/twig"  : "1.0.*"

```

Then, install using composer php composer.phar update

Then, enable the module in `APPPATH/bootstrap.php` by adding it to the modules initialization:

```
Kohana::modules(array(
	// ... all your other modules ...
	'twig'       => MODPATH.'kohana-twig',       // Twig templating engine
));

```

This module was designed for Kohana 3.3, but can be easily made to work with Kohana 3.2 by changing all filenames within the `classes/` directory to lowercase.

Usage
-----

[](#usage)

Use Twigs just as you use would use Kohana Views. By default, your Twig files go into the `twigs` directory anywhere in the cascading filesystem, and have a `.html` extension. (Both of these settings can be configured.) For example, suppose you have a Twig file at `APPPATH/twigs/main.html`, with contents:

```
Hello, {{ name }}

```

Inside your action, you would attach the Twig as follows:

```
$twig = Twig::factory('main');
$twig->name = 'Tom';
$this->response->body($twig);

```

Your Twig files can also reference other templates by name, which will be located using the cascading filesystem. Note that the extension of the twig file is omitted; in the following Twig template example, a file called `template.html` would be located in the cascading filesystem:

```
{% extends "template" %}

```

For more information on Twig templates, see [Twig for Template Designers](http://twig.sensiolabs.org/doc/templates.html)

Configuration
-------------

[](#configuration)

Default configuration is kept in `MODPATH/twig/config/twig.php`. To override it, you can create a config file at `APPPATH/config/twig.php` (or in the `config/` directory of any module that gets loaded before this one) that specifies values to any options you'd like to change.

Extending
---------

[](#extending)

Twig offers many ways to extend the base templating environment. In kohana-twig, this can be achieved by overriding the static `Twig::env()`method. To do so, you can define the class `APPPATH/classes/Twig.php` as follows:

```
class Twig extends Kohana_Twig {

	protected static function env()
	{
		// Instantiate the base Twig environment from parent class.
		$env = parent::env();

		// Customize as needed.
		$env->addExtension(new Twig_Extension_Example);
		// ... do more stuff if you'd like ...

		return $env;
	}

} // End Twig

```

Contributing
------------

[](#contributing)

Contributions are always welcome and appreciated. Since this is a Kohana module, the main thing I ask is that the code conforms to [Kohana's Conventions and Style](http://kohanaframework.org/3.3/guide/kohana/conventions). If you're not familiar with them, please read them over thoroughly.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

4306d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2430962?v=4)[Gilles Paquette](/maintainers/paquettg)[@paquettg](https://github.com/paquettg)

---

Top Contributors

[![tommcdo](https://avatars.githubusercontent.com/u/1991483?v=4)](https://github.com/tommcdo "tommcdo (35 commits)")[![MisterGlass](https://avatars.githubusercontent.com/u/272814?v=4)](https://github.com/MisterGlass "MisterGlass (13 commits)")[![paquettg](https://avatars.githubusercontent.com/u/2430962?v=4)](https://github.com/paquettg "paquettg (8 commits)")[![tchemineau](https://avatars.githubusercontent.com/u/361517?v=4)](https://github.com/tchemineau "tchemineau (6 commits)")[![arteymix](https://avatars.githubusercontent.com/u/1318477?v=4)](https://github.com/arteymix "arteymix (3 commits)")[![fmasa](https://avatars.githubusercontent.com/u/5658260?v=4)](https://github.com/fmasa "fmasa (2 commits)")[![enov](https://avatars.githubusercontent.com/u/4045110?v=4)](https://github.com/enov "enov (2 commits)")[![guss77](https://avatars.githubusercontent.com/u/381782?v=4)](https://github.com/guss77 "guss77 (1 commits)")

---

Tags

twigkohanatemplating

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tommcdo-kohana-twig/health.svg)

```
[![Health](https://phpackages.com/badges/tommcdo-kohana-twig/health.svg)](https://phpackages.com/packages/tommcdo-kohana-twig)
```

###  Alternatives

[timber/timber

Create WordPress themes with beautiful OOP code and the Twig Template Engine

5.7k3.7M130](/packages/timber-timber)[symfony/ux-twig-component

Twig components for Symfony

22018.6M349](/packages/symfony-ux-twig-component)[symfony/ux-live-component

Live components for Symfony

1647.0M126](/packages/symfony-ux-live-component)[october/rain

October Rain Library

1601.7M82](/packages/october-rain)[helsingborg-stad/municipio

A bootstrap theme for creating municipality sites.

4028.5k10](/packages/helsingborg-stad-municipio)[symfony/ux-toolkit

A tool to easily create a design system in your Symfony app with customizable, well-crafted Twig components

16126.1k1](/packages/symfony-ux-toolkit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
