Add UIBlocks to twig (WIP)

This commit is contained in:
Eric
2021-01-13 16:35:01 +01:00
parent 2b798baffc
commit 77808ecd41
23 changed files with 929 additions and 154 deletions

View File

@@ -6,6 +6,7 @@
namespace Combodo\iTop\Application\TwigBase\Twig;
use Combodo\iTop\Application\TwigBase\UI\UIBlockExtension;
use IssueLog;
use Twig\Environment;
use Twig_Environment;
@@ -64,15 +65,13 @@ class TwigHelper
public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = array())
{
$oLoader = new Twig_Loader_Filesystem($sViewPath);
foreach ($aAdditionalPaths as $sAdditionalPath)
{
foreach ($aAdditionalPaths as $sAdditionalPath) {
$oLoader->addPath($sAdditionalPath);
}
$oTwig = new Twig_Environment($oLoader);
Extension::RegisterTwigExtensions($oTwig);
if (!utils::IsDevelopmentEnvironment())
{
if (!utils::IsDevelopmentEnvironment()) {
// Disable the cache in development environment
$sLocalPath = utils::LocalPath($sViewPath);
$sLocalPath = str_replace('env-'.utils::GetCurrentEnvironment(), 'twig', $sLocalPath);
@@ -80,6 +79,8 @@ class TwigHelper
$oTwig->setCache($sCachePath);
}
$oTwig->addExtension(new UIBlockExtension());
return $oTwig;
}
@@ -117,18 +118,12 @@ class TwigHelper
*/
public static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension = self::DEFAULT_FILE_TYPE)
{
try
{
try {
return $oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams);
}
catch (Twig_Error $e)
{
if (!utils::StartsWith($e->getMessage(), 'Unable to find template'))
{
} catch (Twig_Error $e) {
if (!utils::StartsWith($e->getMessage(), 'Unable to find template')) {
IssueLog::Error($e->getMessage());
}
else
{
} else {
IssueLog::Debug($e->getMessage());
}
}