From c3c49fe822e7e333fac4a10e7cca9f46debc6819 Mon Sep 17 00:00:00 2001
From: mcramer <m.cramer@pixcept.de>
Date: Mon, 08 Jul 2013 09:55:17 -0400
Subject: [PATCH] - Implemented element counter variable for loops   ->setLoop('abc', $content);   will automatically add a   ->setVar('_abc', count($content))   IMPORTANT: template variables and loop names starting with _ are not allowed anymore, those are reserved for the counters!

---
 interface/lib/classes/tpl.inc.php |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/interface/lib/classes/tpl.inc.php b/interface/lib/classes/tpl.inc.php
index 72d0dfe..bedf7d1 100644
--- a/interface/lib/classes/tpl.inc.php
+++ b/interface/lib/classes/tpl.inc.php
@@ -192,12 +192,12 @@
             if (is_array($k)) {
                 foreach($k as $key => $value){
                     $key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
-                    if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
+                    if (preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $key) && $value !== null ) {
                         $this->_vars[$key] = $value;
                     }
                 }
             } else {
-                if (preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
+                if (preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $k) && $v !== null) {
                     if ($this->OPTIONS['CASELESS']) $k = strtolower($k);
                     $this->_vars[trim($k)] = $v;
                 } else {
@@ -300,12 +300,14 @@
          */
         public function setLoop($k, $v)
         {
-            if (is_array($v) && preg_match('/^[A-Za-z_]+[A-Za-z0-9_]*$/', $k)) {
+            if (is_array($v) && preg_match('/^[A-Za-z]+[A-Za-z0-9_]*$/', $k)) {
                 $k = ($this->OPTIONS['CASELESS']) ? strtolower(trim($k)) : trim($k);
                 $this->_arrvars[$k] = array();
                 if ($this->OPTIONS['SET_LOOP_VAR'] && !empty($v)) $this->setvar($k, 1);
                 if (($this->_arrvars[$k] = $this->_arrayBuild($v)) == false) {
                     vlibTemplateError::raiseError('VT_WARNING_INVALID_ARR', WARNING, $k);
+                } else {
+                    $this->vars['_'.$k] = count($v);
                 }
             }
             return true;

--
Gitblit v1.9.1