Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
TwigView class for CakePHP
PHP JavaScript
tag: 1.0.1

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
vendors
views
.gitignore
.gitmodules
README

README

/**
 * A CakePHP view class for Twig.
 *
 * @version 1.0
 * @package twig.views
 * @subpackage twig.views.twig
 * @author Paul Redmond <paulrredmond@gmail.com>
 * @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 :)

Installation:
--------------------------------------------------------------------------------
* Run "git clone git@github.com:paulredmond/cakephp-twig.git twig" from your plugins folder or APP/plugins folder.
* Run "git submodule init"
* Run "git submodule update"

Setup:
--------------------------------------------------------------------------------
* 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 http://www.twig-project.org/doc/recipes.html#customizing-the-syntax
		* 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 - https://github.com/paulredmond/cakephp-twig/issues


Notes
--------------------------------------------------------------------------------
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
--------------------------------------------------------------------------------
@todo Properly add Twig vendor files as a submodule

Changelog
--------------------------------------------------------------------------------
21-Jun-2011
	- Changed default extension from "twg" to "twig"
	- Added lexer support

References
--------------------------------------------------------------------------------
* Twig Documentation - http://www.twig-project.org/documentation
* Twig Extensions - http://www.twig-project.org/doc/extensions/index.html
* Twig GitHub repo - https://github.com/fabpot/Twig
Something went wrong with that request. Please try again.