From 9a68fbff7a56189ea5c69b94f7d081720a725154 Mon Sep 17 00:00:00 2001 From: RobinDev Date: Thu, 5 Oct 2023 10:09:44 +0200 Subject: [PATCH 1/2] Permit data inheritance over fetch and layout --- src/Template/Template.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Template/Template.php b/src/Template/Template.php index db11a9f..86cd1e3 100644 --- a/src/Template/Template.php +++ b/src/Template/Template.php @@ -110,7 +110,7 @@ public function __toString() /** * Assign or get template data. * @param array $data - * @return mixed + * @return array */ public function data(array $data = null) { @@ -118,7 +118,7 @@ public function data(array $data = null) return $this->data; } - $this->data = array_merge($this->data, $data); + return $this->data = array_merge($this->data, $data); } /** @@ -196,7 +196,7 @@ public function render(array $data = array()) public function layout($name, array $data = array()) { $this->layoutName = $name; - $this->layoutData = $data; + $this->layoutData = array_merge($this->data, $data); } /** @@ -311,9 +311,9 @@ public function section($name, $default = null) * @param array $data * @return string */ - public function fetch($name, array $data = array()) + public function fetch($name, array $data = array(), bool $only = true) { - return $this->engine->render($name, $data); + return $this->engine->render($name, $only ? $data : array_merge($this->data, $data)); } /** From 2c5a00bf709fddd7940ae437b6bdc2bd0bad4051 Mon Sep 17 00:00:00 2001 From: RobinDev Date: Sun, 12 Nov 2023 10:36:52 +0100 Subject: [PATCH 2/2] update insert to avoid code repetition and apply data --- src/Template/Template.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Template/Template.php b/src/Template/Template.php index 86cd1e3..70775a8 100644 --- a/src/Template/Template.php +++ b/src/Template/Template.php @@ -311,9 +311,9 @@ public function section($name, $default = null) * @param array $data * @return string */ - public function fetch($name, array $data = array(), bool $only = true) + public function fetch($name, array $data = array(), bool $useTemplateData = false) { - return $this->engine->render($name, $only ? $data : array_merge($this->data, $data)); + return $this->engine->render($name, $useTemplateData ? array_merge($this->data, $data) : $data); } /** @@ -322,9 +322,9 @@ public function fetch($name, array $data = array(), bool $only = true) * @param array $data * @return null */ - public function insert($name, array $data = array()) + public function insert($name, array $data = array(), bool $useTemplateData = false) { - echo $this->engine->render($name, $data); + echo $this->fetch($name, $data, $useTemplateData); } /**