megumi/wp-twig

0.5.0 2015-09-30 14:49 UTC

This package is not auto-updated.

Last update: 2024-05-11 16:12:48 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Integrates Twig template engine to WordPress.

Installation

Create a composer.json in your plugin root or mu-plugins

{
    "require": {
        "megumi/wp-twig": "*"
    }
}

Place the following code into your plugin.

require_once dirname( __FILE__ ) . '/vendor/autoload.php';

Then:

$ composer install

How to use

$twig = new Twig_Environment( new Twig_Loader_String() );
$twig->addExtension( new Megumi\WP\Twig_Extension() );

$content = $twig->render( '{{ name | esc_html }}', array( 'name' => '<strong>' ) );
$this->assertSame( '&lt;strong&gt;', $content );

Twig filter extensions for WordPress

  • esc_html
  • esc_attr
  • esc_textarea
  • esc_url
  • esc_js