From 1c2fdb98b1c7fbd85aa086641dd47bc9bd03c8eb Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 10 Mar 2016 18:41:23 +0100 Subject: [PATCH] Add method assignAll() to pageBuilder to assign an array of data --- index.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/index.php b/index.php index 850b350e..9100044e 100644 --- a/index.php +++ b/index.php @@ -637,6 +637,29 @@ public function assign($what,$where) $this->tpl->assign($what,$where); } + /** + * Assign an array of data to the template builder. + * + * @param array $data Data to assign. + * + * @return false if invalid data. + */ + public function assignAll($data) + { + // Lazy initialization + if ($this->tpl === false) { + $this->initialize(); + } + + if (empty($data) || !is_array($data)){ + return false; + } + + foreach ($data as $key => $value) { + $this->assign($key, $value); + } + } + // Render a specific page (using a template). // e.g. pb.renderPage('picwall') public function renderPage($page)