diff --git a/application/itopwebpage.class.inc.php b/application/itopwebpage.class.inc.php index 4f7c66156..aec9b29a3 100644 --- a/application/itopwebpage.class.inc.php +++ b/application/itopwebpage.class.inc.php @@ -1139,7 +1139,7 @@ EOF ] ); - $oTwigEnv = TwigHelper::GetTwigEnvironment(APPROOT.'templates/'); + $oTwigEnv = TwigHelper::GetTwigEnvironment(BlockRenderer::TWIG_BASE_PATH, BlockRenderer::TWIG_ADDITIONAL_PATHS); // Send headers if ($this->GetOutputFormat() === 'html') diff --git a/sources/Renderer/BlockRenderer.php b/sources/Renderer/BlockRenderer.php index 84a341f2f..89981bcb4 100644 --- a/sources/Renderer/BlockRenderer.php +++ b/sources/Renderer/BlockRenderer.php @@ -34,6 +34,9 @@ use ReflectionClass; */ class BlockRenderer { + public const TWIG_BASE_PATH = APPROOT.'templates/'; + public const TWIG_ADDITIONAL_PATHS = [APPROOT.'images/']; + /** @var \Twig_Environment $oTwigEnv Singleton used during rendering */ protected static $oTwigEnv; @@ -72,7 +75,7 @@ class BlockRenderer { if(null === static::$oTwigEnv) { - static::$oTwigEnv = TwigHelper::GetTwigEnvironment(APPROOT.'templates/'); + static::$oTwigEnv = TwigHelper::GetTwigEnvironment(static::TWIG_BASE_PATH, static::TWIG_ADDITIONAL_PATHS); } $this->oBlock = $oBlock; diff --git a/sources/application/TwigBase/Twig/TwigHelper.php b/sources/application/TwigBase/Twig/TwigHelper.php index b9aae84e6..7483ffa6b 100644 --- a/sources/application/TwigBase/Twig/TwigHelper.php +++ b/sources/application/TwigBase/Twig/TwigHelper.php @@ -39,6 +39,11 @@ class TwigHelper * @since 2.8.0 */ const ENUM_FILE_TYPE_CSS = 'css'; + /** + * @var string ENUM_FILE_TYPE_SVG + * @since 2.8.0 + */ + const ENUM_FILE_TYPE_SVG = 'svg'; /** * @var string DEFAULT_FILE_TYPE @@ -51,12 +56,19 @@ class TwigHelper * This is not a singleton as we might want to use several instances with different base path. * * @param string $sViewPath + * @param array $aAdditionalPaths * * @return \Twig_Environment + * @throws \Twig\Error\LoaderError */ - public static function GetTwigEnvironment($sViewPath) + public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = array()) { $oLoader = new Twig_Loader_Filesystem($sViewPath); + foreach ($aAdditionalPaths as $sAdditionalPath) + { + $oLoader->addPath($sAdditionalPath); + } + $oTwig = new Twig_Environment($oLoader); Extension::RegisterTwigExtensions($oTwig); if (!utils::IsDevelopmentEnvironment()) @@ -64,7 +76,7 @@ class TwigHelper // Disable the cache in development environment $sLocalPath = utils::LocalPath($sViewPath); $sLocalPath = str_replace('env-'.utils::GetCurrentEnvironment(), 'twig', $sLocalPath); - $sCachePath = utils::GetCachePath().$sLocalPath; + $sCachePath = utils::GetCachePath().'twig/'.$sLocalPath; $oTwig->setCache($sCachePath); }