From 0a428423afbb84ef79839f1925a0b5cbee3942a7 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sun, 19 Nov 2017 14:58:47 +1100 Subject: [PATCH] Twig partial() function should not throw exception This allows checking if a partial exists --- modules/cms/twig/Extension.php | 5 +++-- modules/cms/twig/PartialNode.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/cms/twig/Extension.php b/modules/cms/twig/Extension.php index 8d6451f83..f123a744e 100644 --- a/modules/cms/twig/Extension.php +++ b/modules/cms/twig/Extension.php @@ -98,11 +98,12 @@ class Extension extends Twig_Extension * Renders a partial. * @param string $name Specifies the partial name. * @param array $parameters A optional list of parameters to pass to the partial. + * @param bool $throwException Throw an exception if the partial is not found. * @return string Returns the partial contents. */ - public function partialFunction($name, $parameters = []) + public function partialFunction($name, $parameters = [], $throwException = false) { - return $this->controller->renderPartial($name, $parameters); + return $this->controller->renderPartial($name, $parameters, $throwException); } /** diff --git a/modules/cms/twig/PartialNode.php b/modules/cms/twig/PartialNode.php index baf9778bb..003bcf2fc 100644 --- a/modules/cms/twig/PartialNode.php +++ b/modules/cms/twig/PartialNode.php @@ -37,6 +37,7 @@ class PartialNode extends Twig_Node ->write("echo \$this->env->getExtension('Cms\Twig\Extension')->partialFunction(") ->subcompile($this->getNode('nodes')->getNode(0)) ->write(", \$context['__cms_partial_params']") + ->write(", true") ->write(");\n") ;