Skip to content
maxcal edited this page Mar 22, 2012 · 24 revisions

Twigpress

Twig + Wordpress = Twigpress

Twigpress is a wordpress plugin that allows template designers to create wordpress templates with Twig.
Twig is a PHP template engine with great functionality and syntax.

Multi-paradigm design.

Twigpress is created with alot of flexiblity in mind.

As a drop in replacement for PHP.

When used with template autoloading and registerGlobalFunctions twigpress can be used as a drop in syntax replacement for php.

// /themes/yourTheme/index.php
$Twigpress->registerGlobalFunctions();
echo $Twigpress->autoDisplay($wp_query);

Renders:

{# themes/yourTheme/index.html.twig #}
Hello {{ bloginfo( 'name' ) }}

As Model View Controller

You can use it as MVC by using the index.php (Controller) to set posts (Model) and renderindex.html.twig (view)

  // index.php
  $my_query = new WP_Query('posts_per_page=10');
  $Twigpress->display('index.html.twig', array('posts' => $my_query));

Coding Conventions:

  1. Convention over Configuration
    Defaults should be as secure and useful as possible on a live site. [@todo] - the ideas is Themes can declare there own configuration (via ini or json) which will override the plugin config.

  2. Dependency Injection
    Use inversion of control and dependency injection when possible. Avoid using WP globals or functions directly if possible.

  3. TDD
    All public methods should be unit tested.

  4. File naming
    Use the PEAR conventions, not the Wordpress Conventions.

Mission:

  1. To make it fun and creative to create wordpress themes with Twig.
  2. To be tested and reliable.
  3. To offer flexibility to theme designers.