]> git.mxchange.org Git - friendica.git/commitdiff
Add {{ if a==b }} and {{ if a!=b }} to templates
authorFabio Comuni <fabrix.xm@gmail.com>
Mon, 13 Jun 2011 16:02:40 +0000 (18:02 +0200)
committerFabio Comuni <fabrix.xm@gmail.com>
Mon, 13 Jun 2011 16:02:40 +0000 (18:02 +0200)
include/template_processor.php

index 3dc249c403fc6b3c3513eb84994d1211b87301d9..a2c24b00bc0bc30e705ff7cef98f0331763e335b 100644 (file)
                 * IF node
                 * 
                 * {{ if <$var> }}...{{ endif }}
+                * {{ if <$var>==<val|$var> }}...{{ endif }}
+                * {{ if <$var>!=<val|$var> }}...{{ endif }}
                 */
                private function _replcb_if($args){
-                       $val = $this->_get_var($args[2]);
+                       
+                       if (strpos($args[2],"==")>0){
+                               list($a,$b) = array_map("trim",explode("==",$args[2]));
+                               $a = $this->_get_var($a);
+                               if ($b[0]=="$") $b =  $this->_get_var($b);
+                               $val = ($a == $b);
+                       } else if (strpos($args[2],"!=")>0){
+                               list($a,$b) = explode("!=",$args[2]);
+                               $a = $this->_get_var($a);
+                               if ($b[0]=="$") $b =  $this->_get_var($b);
+                               $val = ($a != $b);
+                       } else {
+                               $val = $this->_get_var($args[2]);
+                       }
                        return ($val?$args[3]:"");
                }