Skip to content

megumi-wp-composer/wp-twig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

megumi/wp-twig

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