Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
TwigView class for CakePHP
PHP JavaScript
branch: master

This branch is 59 commits behind develop

Fetching latest commit…

Cannot retrieve the latest commit at this time

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

README

/**
 * A CakePHP view class for Twig.
 *
 * @version 1.0.2
 * @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 test/support for CakePHP 2.0 branch.

Changelog
--------------------------------------------------------------------------------
21-Oct-2011
    - Updated Twig library to 1.2
    - Added extension support for basic functions (like debug)
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.