TwigView class for CakePHP
PHP JavaScript
Pull request Compare This branch is 59 commits behind develop.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


 * A CakePHP view class for Twig.
 * @version 1.0.2
 * @package twig.views
 * @subpackage twig.views.twig
 * @author Paul Redmond <>
 * @license MIT

There are a few other TwigView implementations out there already. I built my own because it helped me to learn more about dropping in a custom view/template engine into CakePHP. I am pretty happy with the results :)

* Run "git clone twig" from your plugins folder or APP/plugins folder.
* Run "git submodule init"
* Run "git submodule update"

* Add/update app/app_controller.php to
	public $view = 'Twig.Twig';
* Create APP/tmp/twig/cache and make sure it's writable on the server, or define your own path in the bootstrap and make that that path is writable.
	In APP/bootstrap.php:
	define( 'TWIG_CACHE_PATH', '/path/to/writable/cache' );
* Configure non-default settings in APP/config/core.php
	Configuration options:
		- ext: the file extension used to render twig templates "with or without the ."
		- debug_comments: TwigView adds render time and full path to each rendered twig template. You can disable by setting to false (default: true).
		- lexer: TwigLexer object allows for custom syntax in block delimiters. For more info see
		* Debug comments are never rendered in any circumstance if debug is false, ie. Configure::write('debug', 0);
	# Sample custom config.
	Configure::write('Twig', array(
		'ext' => '.html', # Doesn't matter if "." is included, either way, it will work.
		'debug_comments' => false,
		'lexer' => array( # Ruby ERB syntax example.
		    'tag_comment'  => array('<%#', '%>'),
		    'tag_block'    => array('<%', '%>'),
		    'tag_variable' => array('<%=', '%>'),
* Report bugs or performance issues on GitHub please -

Twig doesn't care what file extension is used, and I chose the default of "twig". Feel free to change it to whatever you want, I've provided a configuration setting for the extension. I opted to rewrite the View::element() method which may require more looping to find the correct template. I recommend sticking with twig templates for all views, but I also understand that some application may already have many ctp views.

@todo test/support for CakePHP 2.0 branch.

    - Updated Twig library to 1.2
    - Added extension support for basic functions (like debug)
	- Changed default extension from "twg" to "twig"
	- Added lexer support

* Twig Documentation -
* Twig Extensions -
* Twig GitHub repo -