A WordPress Plugin allowing the usage of Twig, Blade, Mustache and Smarty templates in any WordPress view.
Via git in the WordPress plugins directory
$ git clone https://github.com/MartinSotirov/modern-templates.git
add_filter( 'wpmt_engine', 'make_twig_engine', 2, 10 );
function make_twig_engine( $engine, $WPMT ) {
$settings = array(
'templatePath' => get_stylesheet_directory() . '/templates',
'cachePath' => get_stylesheet_directory() . '/templates/cache'
);
$engine = $WPMT->makeEngine('Twig', $settings);
return $engine;
}
add_filter( 'wpmt_engine', 'make_blade_engine', 2, 10 );
function make_blade_engine( $engine, $WPMT ) {
$settings = array(
'templatePath' => get_stylesheet_directory() . '/templates',
'cachePath' => get_stylesheet_directory() . '/templates/cache'
);
$engine = $WPMT->makeEngine('Blade', $settings);
return $engine;
}
add_filter( 'wpmt_engine', 'make_smarty_engine', 2, 10 );
function make_smarty_engine( $engine, $WPMT ) {
$settings = array(
'templatePath' => get_stylesheet_directory() . '/templates',
'cachePath' => get_stylesheet_directory() . '/templates/cache',
'compilePath' => get_stylesheet_directory() . '/templates/compile',
'configPath' => get_stylesheet_directory() . '/templates/config',
);
$engine = $WPMT->makeEngine('Smarty', $settings);
return $engine;
}
add_filter( 'wpmt_engine', 'make_mustache_engine', 2, 10 );
function make_mustache_engine( $engine, $WPMT ) {
$settings = array(
'templatePath' => get_stylesheet_directory() . '/templates',
'cachePath' => get_stylesheet_directory() . '/templates/cache',
'partialsPath' => get_stylesheet_directory() . '/templates/partials',
);
$engine = $WPMT->makeEngine('Mustache', $settings);
return $engine;
}
The plugin abstracts away the technicalities of all four templating engines and provides
a consistent API for rendering. With the WordPress plugin enabled, you have access to the
global variable $WPMT. Use it to get an instance of the templating engine you instanciated
in the wpmt_engine
hook
$twig = $WPMT->getEngine();
$data = [
'wp_head' => $WPMT->get('wp_head'),
'wp_footer' => $WPMT->get('wp_footer'),
'body_class' => $WPMT->get('body_class'),
'post' => get_queried_object(),
];
echo $twig->render('single-post.html', $data);
Please see CHANGELOG for more information what has changed recently.
$ bin/install-wp-tests.sh
$ phpunit
None so far
GPL 2. Please see License File for more information.