Skip to content

Instantly share code, notes, and snippets.

@jarednova
Last active June 6, 2019 12:35
Show Gist options
  • Save jarednova/3f6ff7e9163f1772fcb361efdb3230fa to your computer and use it in GitHub Desktop.
Save jarednova/3f6ff7e9163f1772fcb361efdb3230fa to your computer and use it in GitHub Desktop.
/**
* @param Twig_LoaderInterface $loader
* @param array $environment_args
*
* @return Twig_Environment
*/
public function get_twig_environment( $loader, $environment_args ) {
return new \Twig\Environment( $loader, $environment_args );
}
/**
* @param array $template_paths
*
* @return Twig_Loader_Filesystem
*/
public function get_twig_loader_filesystem( $template_paths ) {
return new \Twig\Loader\FilesystemLoader( $template_paths );
}
<?php
/**
* Class WPML_Twig_Template_Loader
*/
class WPML_Twig_Template_Loader {
/**
* @var array
*/
private $paths;
/**
* WPML_Twig_Template_Loader constructor.
*
* @param array $paths
*/
public function __construct( array $paths ) {
$this->paths = $paths;
}
/**
* @return WPML_Twig_Template
*/
public function get_template() {
$twig_loader = new \Twig\Loader\FilesystemLoader( $this->paths );
$environment_args = array();
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
$environment_args['debug'] = true;
}
$twig = new \Twig\Environment( $twig_loader, $environment_args );
return new WPML_Twig_Template( $twig );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment