Skip to content

pieceofcake2/twig-view

 
 

Repository files navigation

TwigView plugin for CakePHP 2

GitHub License Packagist Version PHP CakePHP Twig CI Codecov

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

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/ and templates/ directories
  • Pre-compilation: Compile templates for production performance
  • PSR-4 Namespaces: Modern PHP architecture

Fork History

This project is based on the following repositories:

  1. m3nt0r-legacy/cakephp-twig-view - Original implementation by Kjell Bublitz
  2. predominant/TwigView - Fork by Graham Weldon (archived in 2019) - Direct fork source
  3. cakephp/legacy-twig-view - CakePHP community version (formerly WyriHaximus/TwigView, deprecated)
  4. 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.

Languages

  • PHP 99.7%
  • Other 0.3%