From afb03bd83f190d37b9be72928bdf2fc7b51b94fb Mon Sep 17 00:00:00 2001 From: David Remer Date: Thu, 19 May 2022 12:54:18 +0300 Subject: [PATCH] Add twig:generate-cache command [MAILPOET-3985] --- mailpoet/RoboFile.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mailpoet/RoboFile.php b/mailpoet/RoboFile.php index 4ac9caf1c3..be3a1c9fdd 100644 --- a/mailpoet/RoboFile.php +++ b/mailpoet/RoboFile.php @@ -1,6 +1,10 @@ run($generatorName); } + public function twigGenerateCache() { + + $templatePath = __DIR__ . '/views/'; // \MailPoet\Config\Env::$viewsPath . '/' + define('ABSPATH', (dirname(__DIR__) . '/wordpress')); + $renderer = new \MailPoet\Config\Renderer( + false, + __DIR__ . '/generated/twig', + new TwigFileSystem($templatePath) + ); + $twig = $renderer->getTwig(); + foreach ($this->rsearch($templatePath, ['html']) as $template) { + $path = substr($template, strlen($templatePath)); + $twig->load($path); + } + } + protected function rsearch($folder, $extensions = []) { $dir = new RecursiveDirectoryIterator($folder); $iterator = new RecursiveIteratorIterator($dir);