Skip to content

Instantly share code, notes, and snippets.

@thomasmery
Last active January 26, 2016 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasmery/beff71a6a2b82699bce9 to your computer and use it in GitHub Desktop.
Save thomasmery/beff71a6a2b82699bce9 to your computer and use it in GitHub Desktop.
Twig template engine setup for Wordpress and ACF -
<?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