pieceofcake2 / twig-view
Twig for CakePHP 2.x
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 41
Type:cakephp-plugin
pkg:composer/pieceofcake2/twig-view
Requires
- php: >=8.1
- composer/installers: *
- pieceofcake2/cakephp: ^2.12
- twig/twig: ^3.21
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6
- pieceofcake2/app: ^2.2
- pieceofcake2/phpstan-cakephp2: ^0.2.1
Replaces
- wyrihaximus/twig-view: ^1.0
README
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.
Requirements
- PHP 8.1+
- CakePHP 2.12+
- Twig 3.x
Installation
Install via Composer:
composer require pieceofcake2/twig-view
Load the plugin in your app/Config/bootstrap.php:
CakePlugin::load('TwigView'); // or CakePlugin::loadAll();
Quick Start
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 %}
Documentation
- 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
Features
- 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
Fork History
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.