diff --git a/sources/Renderer/BlockRenderer.php b/sources/Renderer/BlockRenderer.php index b77c3268f..84a341f2f 100644 --- a/sources/Renderer/BlockRenderer.php +++ b/sources/Renderer/BlockRenderer.php @@ -41,6 +41,7 @@ class BlockRenderer * Helper to use directly in TWIG to render a block and its sub blocks * * @param \Combodo\iTop\Application\UI\iUIBlock $oBlock + * @param array $aContextParams * * @return string * @throws \ReflectionException @@ -48,14 +49,16 @@ class BlockRenderer * @throws \Twig\Error\RuntimeError * @throws \Twig\Error\SyntaxError */ - public static function RenderBlockTemplates(iUIBlock $oBlock) + public static function RenderBlockTemplates(iUIBlock $oBlock, $aContextParams = []) { - $oSelf = new static($oBlock); + $oSelf = new static($oBlock, $aContextParams); return $oSelf->RenderTemplates(); } /** @var \Combodo\iTop\Application\UI\iUIBlock $oBlock */ protected $oBlock; + /** @var array $aContextParams Optional context parameters to pass to the template during rendering */ + protected $aContextParams; /** @var \Combodo\iTop\Renderer\RenderingOutput $oRenderingOutput */ protected $oRenderingOutput; @@ -63,8 +66,9 @@ class BlockRenderer * BlockRenderer constructor. * * @param \Combodo\iTop\Application\UI\iUIBlock $oBlock + * @param array $aContextParams */ - public function __construct(iUIBlock $oBlock) + public function __construct(iUIBlock $oBlock, $aContextParams = []) { if(null === static::$oTwigEnv) { @@ -72,6 +76,7 @@ class BlockRenderer } $this->oBlock = $oBlock; + $this->aContextParams = $aContextParams; $this->ResetRenderingOutput(); } @@ -125,7 +130,7 @@ class BlockRenderer { $sOutput = TwigHelper::RenderTemplate( static::$oTwigEnv, - [$this->GetBlockParameterNameForTemplate() => $this->oBlock], + $this->GetTemplateParameters(), $this->oBlock::GetHtmlTemplateRelPath(), TwigHelper::ENUM_FILE_TYPE_HTML ); @@ -150,7 +155,7 @@ class BlockRenderer { $sOutput = TwigHelper::RenderTemplate( static::$oTwigEnv, - [$this->GetBlockParameterNameForTemplate() => $this->oBlock], + $this->GetTemplateParameters(), $this->oBlock::GetJsTemplateRelPath(), TwigHelper::ENUM_FILE_TYPE_JS ); @@ -175,7 +180,7 @@ class BlockRenderer { $sOutput = TwigHelper::RenderTemplate( static::$oTwigEnv, - [$this->GetBlockParameterNameForTemplate() => $this->oBlock], + $this->GetTemplateParameters(), $this->oBlock::GetCssTemplateRelPath(), TwigHelper::ENUM_FILE_TYPE_CSS ); @@ -247,13 +252,14 @@ HTML; } /** - * Return the name of the parameter used in the template to access the block object (class short name = without namespace) + * Return an associative array of parameters for the template. + * Contains oUIBlock for the current block and optionally some others. * - * @return string - * @throws \ReflectionException + * @return array */ - protected function GetBlockParameterNameForTemplate() + protected function GetTemplateParameters() { - return 'oUIBlock'; + return array_merge(['oUIBlock' => $this->oBlock], $this->aContextParams); + } } \ No newline at end of file diff --git a/sources/application/TwigBase/Twig/Extension.php b/sources/application/TwigBase/Twig/Extension.php index 2b07f27a0..cfcc23f67 100644 --- a/sources/application/TwigBase/Twig/Extension.php +++ b/sources/application/TwigBase/Twig/Extension.php @@ -150,8 +150,8 @@ class Extension // Function to render a UI block (HTML, inline CSS, inline JS) and its sub blocks directly in the TWIG // Usage in twig: {{ render_block(oBlock) }} /** @since 2.8.0 */ - $oTwigEnv->addFunction(new Twig_SimpleFunction('render_block', function(iUIBlock $oBlock){ - return BlockRenderer::RenderBlockTemplates($oBlock); + $oTwigEnv->addFunction(new Twig_SimpleFunction('render_block', function(iUIBlock $oBlock, $aContextParams = []){ + return BlockRenderer::RenderBlockTemplates($oBlock, $aContextParams); }, ['is_safe' => ['html']])); } diff --git a/templates/components/popover-menu/layout.html.twig b/templates/components/popover-menu/layout.html.twig index 2cc54d06f..69060706e 100644 --- a/templates/components/popover-menu/layout.html.twig +++ b/templates/components/popover-menu/layout.html.twig @@ -3,7 +3,7 @@ {% if aSection.aItems|length > 0 %}
{% endif %} diff --git a/templates/layouts/top-bar/layout.html.twig b/templates/layouts/top-bar/layout.html.twig index 740849e34..b2d2c696b 100644 --- a/templates/layouts/top-bar/layout.html.twig +++ b/templates/layouts/top-bar/layout.html.twig @@ -1,13 +1,13 @@ \ No newline at end of file diff --git a/templates/pages/backoffice/layout.html.twig b/templates/pages/backoffice/layout.html.twig index f13228329..499b1b92e 100644 --- a/templates/pages/backoffice/layout.html.twig +++ b/templates/pages/backoffice/layout.html.twig @@ -33,14 +33,14 @@ {% endblock %} - {{ render_block(aLayouts.oNavigationMenu) }} + {{ render_block(aLayouts.oNavigationMenu, {aPage: aPage}) }}