Modern Twig 3.x support for CakePHP 2.x with PSR-4 namespaces and PHP 8.1+.
This plugin integrates the Twig Templating Language with CakePHP 2, providing access to helpers, elements, and themes.
Note
For CakePHP 5.x, use the official cakephp/twig-view package instead.
- PHP 8.1+
- CakePHP 2.12+
- Twig 3.x
Install via Composer:
composer require pieceofcake2/twig-viewLoad the plugin in your app/Config/bootstrap.php:
CakePlugin::load('TwigView');
// or
CakePlugin::loadAll();Set the view class in your app/Controller/AppController.php:
class AppController extends Controller
{
public $viewClass = 'TwigView.Twig';
}Create templates with .twig extension:
{# app/View/Posts/index.twig #}
{% for post in posts %}
<h2>{{ post.Post.title }}</h2>
<p>{{ post.Post.body }}</p>
{% endfor %}- Function & Filter Reference - Complete list of available Twig functions and filters
- Using Helpers - How to use CakePHP helpers in Twig templates
- Configuration - Advanced configuration options
- Extensions - Popular Twig extensions
- Examples - Example layouts and templates
- CakePHP Integration: Full access to helpers, elements, and themes
- Custom Extensions: Extend Twig with custom filters and functions
- Theme Support: Compatible with CakePHP's themed views
- Plugin Support: Works with both
View/andtemplates/directories - Pre-compilation: Compile templates for production performance
- PSR-4 Namespaces: Modern PHP architecture
This project is based on the following repositories:
- m3nt0r-legacy/cakephp-twig-view - Original implementation by Kjell Bublitz
- predominant/TwigView - Fork by Graham Weldon (archived in 2019) - Direct fork source
- cakephp/legacy-twig-view - CakePHP community version (formerly WyriHaximus/TwigView, deprecated)
- pieceofcake2/twig-view (this repository) - Modernized fork with Twig 3.x and PHP 8.1+ support
The original repositories supported Twig 1.x with CakePHP 2.x but are no longer maintained. This fork updates the codebase to work with modern PHP and Twig versions while maintaining CakePHP 2.x compatibility.