isDir() and $tplDir!='.' and $tplDir!='..') { echo "\n$tplDir\n"; $loader = new Twig_Loader_Filesystem($tplDirRoot.$tplDir); // force auto-reload to always have the latest version of the template $twig = new Twig_Environment($loader, array( 'cache' => $tmpDir, 'auto_reload' => true )); $twig->addExtension(new Twig_Extensions_Extension_I18n()); $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); $twig->addFilter($filter); $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); $twig->addFilter($filter); $filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace($siteRoot, '', $string); }); $twig->addFilter($filter); // // iterate over all your templates foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDirRoot.$tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) { // force compilation if ($file->isFile() and pathinfo($file, PATHINFO_EXTENSION)=='twig') { echo "\t$file\n"; $twig->loadTemplate(str_replace($tplDirRoot.$tplDir.'/', '', $file)); } } } }