setCache($sCachePath); return $oTwig; } /** * Display the twig page based on the name or the operation onto the page specified with SetPage(). * Use this method if you have to insert HTML into an existing page. * * @param \WebPage $oPage * @param string $sViewPath Absolute path of the templates folder * @param string $sTemplateName Name of the twig template, ie MyTemplate for MyTemplate.html.twig * @param array $aParams Params used by the twig template * @param string $sDefaultType default type of the template ('html', 'xml', ...) * * @throws \Exception * @api */ public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = 'html') { $oTwig = self::GetTwigEnvironment($sViewPath); $oPage->add(self::RenderTemplate($oTwig, $aParams, $sTemplateName, $sDefaultType)); $oPage->add_script(self::RenderTemplate($oTwig, $aParams, $sTemplateName, 'js')); $oPage->add_ready_script(self::RenderTemplate($oTwig, $aParams, $sTemplateName, 'ready.js')); } /** * @param \Twig\Environment $oTwig * @param $aParams * @param $sName * @param $sTemplateFileExtension * * @return string */ private static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension) { try { return $oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams); } catch (Twig_Error $e) { if (!utils::StartsWith($e->getMessage(), 'Unable to find template')) { IssueLog::Error($e->getMessage()); } else { IssueLog::Debug($e->getMessage()); } } return ''; } }