]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Add method assignAll() to pageBuilder to assign an array of data
authorArthurHoaro <arthur@hoa.ro>
Thu, 10 Mar 2016 17:41:23 +0000 (18:41 +0100)
committerArthurHoaro <arthur@hoa.ro>
Fri, 18 Mar 2016 18:13:48 +0000 (19:13 +0100)
index.php

index 850b350e9c5ad1c2dbae08c5573b929aaf22749b..9100044e8c5afcdf24f49604f5d498ece2a46b62 100644 (file)
--- a/index.php
+++ b/index.php
@@ -637,6 +637,29 @@ class pageBuilder
         $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)