mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-22 10:08:45 +02:00
TwigBase: Add 2 TWIG functions (get_absolute_url_app_root / get_absolute_url_modules_root)
This commit is contained in:
@@ -127,6 +127,20 @@ class Extension
|
||||
|
||||
return $oConfig->Get($sParamName);
|
||||
}));
|
||||
|
||||
// Function to get iTop's app root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/)
|
||||
// Usage in twig: {{ get_absolute_url_app_root() }}
|
||||
/** @since 2.8.0 */
|
||||
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_absolute_url_app_root', function () {
|
||||
return utils::GetAbsoluteUrlAppRoot();
|
||||
}));
|
||||
|
||||
// Function to get iTop's modules root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/env-zzz/)
|
||||
// Usage in twig: {{ get_absolute_url_modules_root() }}
|
||||
/** @since 2.8.0 */
|
||||
$oTwigEnv->addFunction(new Twig_SimpleFunction('get_absolute_url_modules_root', function () {
|
||||
return utils::GetAbsoluteUrlModulesRoot();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ use WebPage;
|
||||
|
||||
class TwigHelper
|
||||
{
|
||||
const DEFAULT_FILE_TYPE = 'html';
|
||||
|
||||
public static function GetTwigEnvironment($sViewPath)
|
||||
{
|
||||
$oLoader = new Twig_Loader_Filesystem($sViewPath);
|
||||
@@ -47,7 +49,7 @@ class TwigHelper
|
||||
* @throws \Exception
|
||||
* @api
|
||||
*/
|
||||
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = 'html')
|
||||
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = self::DEFAULT_FILE_TYPE)
|
||||
{
|
||||
$oTwig = self::GetTwigEnvironment($sViewPath);
|
||||
$oPage->add(self::RenderTemplate($oTwig, $aParams, $sTemplateName, $sDefaultType));
|
||||
@@ -57,13 +59,13 @@ class TwigHelper
|
||||
|
||||
/**
|
||||
* @param \Twig\Environment $oTwig
|
||||
* @param $aParams
|
||||
* @param $sName
|
||||
* @param $sTemplateFileExtension
|
||||
* @param array $aParams
|
||||
* @param string $sName
|
||||
* @param string $sTemplateFileExtension
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension)
|
||||
public static function RenderTemplate(Environment $oTwig, $aParams, $sName, $sTemplateFileExtension = self::DEFAULT_FILE_TYPE)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user