Last active
January 26, 2016 08:25
-
-
Save thomasmery/beff71a6a2b82699bce9 to your computer and use it in GitHub Desktop.
Twig template engine setup for Wordpress and ACF -
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Setup Twig Templating : http://twig.sensiolabs.org/ | |
* expects a /templates directory to exist in theme directory | |
* | |
* usage with _twig_render wrapper function | |
* _twig_render($template_path, $data_array); | |
* | |
* | |
**/ | |
$loader = new \Twig_Loader_Filesystem(get_stylesheet_directory() . '/templates'); | |
$twig = new \Twig_Environment($loader, array( | |
// only use twig cache in production | |
'cache' => WP_DEBUG?null:get_stylesheet_directory() . '/templates/twig_cache', | |
)); | |
/** | |
* this function is a wrapper for using the globally created $twig instance | |
* | |
**/ | |
function _twig_render ($template_path, $vars = []) { global $twig; return $twig->render($template_path, $vars); }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment