diff --git a/sources/application/TwigBase/Controller/Controller.php b/sources/application/TwigBase/Controller/Controller.php index 4fc482629..4dad3ebba 100644 --- a/sources/application/TwigBase/Controller/Controller.php +++ b/sources/application/TwigBase/Controller/Controller.php @@ -32,7 +32,6 @@ use MetaModel; use ReflectionClass; use SetupPage; use SetupUtils; -use Twig_Error; use utils; use ZipArchive; @@ -158,8 +157,6 @@ abstract class Controller } catch (Exception $e) { - require_once(APPROOT."/setup/setuppage.class.inc.php"); - http_response_code(500); $oP = new ErrorPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("

".Dict::S('UI:FatalErrorMessage')."

\n"); @@ -529,20 +526,7 @@ abstract class Controller { throw new Exception('Not initialized. Call Controller::InitFromModule() or Controller::SetViewPath() before any display'); } - try - { - return $this->m_oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams); - } - catch (Twig_Error $e) - { - // Ignore errors - if (!utils::StartsWith($e->getMessage(), 'Unable to find template')) - { - IssueLog::Error($e->getMessage()); - } - } - - return ''; + return TwigHelper::RenderTemplate($this->m_oTwig, $aParams, $sName, $sTemplateFileExtension, false); } /** diff --git a/sources/application/TwigBase/Twig/TwigHelper.php b/sources/application/TwigBase/Twig/TwigHelper.php index e89824a49..1543efdc4 100644 --- a/sources/application/TwigBase/Twig/TwigHelper.php +++ b/sources/application/TwigBase/Twig/TwigHelper.php @@ -7,6 +7,7 @@ namespace Combodo\iTop\Application\TwigBase\Twig; use Combodo\iTop\Application\TwigBase\UI\UIBlockExtension; +use Exception; use IssueLog; use Twig\Environment; use Twig_Environment; @@ -110,21 +111,30 @@ class TwigHelper * @param array $aParams * @param string $sName * @param string $sTemplateFileExtension + * @param bool $bLogMissingFile * * @return string * @throws \Twig\Error\LoaderError * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError + * @throws \Exception */ - public static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension = self::DEFAULT_FILE_TYPE) + public static function RenderTemplate(Environment $oTwig, array $aParams, string $sName, string $sTemplateFileExtension = self::DEFAULT_FILE_TYPE, bool $bLogMissingFile = true): string { try { return $oTwig->render($sName.'.'.$sTemplateFileExtension.'.twig', $aParams); } catch (Twig_Error $e) { + $sPath = ''; + if ($e->getSourceContext()) { + $sPath = utils::LocalPath($e->getSourceContext()->getPath()).' ('.$e->getLine().') - '; + } + $sMessage = $sPath.$e->getMessage(); if (!utils::StartsWith($e->getMessage(), 'Unable to find template')) { - IssueLog::Error($e->getMessage()); - } else { - IssueLog::Debug($e->getMessage()); + IssueLog::Error($sMessage); + // Todo 3.0 Less violent message + throw new Exception($sMessage); + } elseif ($bLogMissingFile) { + IssueLog::Debug($sMessage); } } diff --git a/sources/application/TwigBase/UI/UIBlockNode.php b/sources/application/TwigBase/UI/UIBlockNode.php index 56f718310..83ef8b69f 100644 --- a/sources/application/TwigBase/UI/UIBlockNode.php +++ b/sources/application/TwigBase/UI/UIBlockNode.php @@ -42,7 +42,8 @@ class UIBlockNode extends Node ->write("ob_end_clean();\n") ->write("if (strlen(\$sHtml) > 0) {\n") ->indent()->write("end(\$context['UIBlockParent'])->AddSubBlock(new \Combodo\iTop\Application\UI\Base\Component\Html\Html(\$sHtml));\n")->outdent() - ->write("}\n") ->write("\$aParams = ") + ->write("}\n") + ->write("\$aParams = ") ->subcompile($oParams) ->raw(";\n");