X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=template.php;h=a20fd64b775964f4ee78e1165961d3ce335f5873;hb=c311c032739b97156dd373b270c0915bf248be76;hp=cbb9466f18d01ef7eed3e17a3a47f7f3a18583d4;hpb=b9ff9266110da0a7c3ddfe08c5d1b8bee4660414;p=wfpl.git diff --git a/template.php b/template.php index cbb9466..a20fd64 100644 --- a/template.php +++ b/template.php @@ -157,12 +157,14 @@ function &tem_push(&$stack = NULL) { # The middle form will be converted to the last form as we use it. -function tem_data_as_rows($value) { +function tem_data_as_rows($value, $key) { if(is_array($value)) { - # numeric keys, is already array of arrays -- expand sub-template for each. - if(array_key_exists(0, $value)) return $value; + # numeric keys + if(array_key_exists(0, $value)) { + if(is_array($value[0])) return $value; # already array of hashes. + else return columnize($value, $key); # key/value pairs -- expand sub-template once. - else return array($value); + } else return array($value); } elseif($value || $value === 0 || $value === '0' || $value === '') { # value -- expand sub-template once using only parent values return array(array()); @@ -213,7 +215,7 @@ function &tem_row_data($tem, $context) if($auto_func) $value = $auto_func($scope['data'][$key], $key, $scope); else $value = $scope['data'][$key]; - $rows = tem_data_as_rows($value); + $rows = tem_data_as_rows($value, $key); if(is_array($value)) $scope['data'][$key] = $rows; return $rows; @@ -324,6 +326,13 @@ function tem_auto_show(&$value) { return $value; } +# 'empty' sections will be shown only if the corresponding data value is the +# empty string +function tem_auto_empty(&$value) { + if($value === '') return true; + return null; +} + # 'nonempty' sections will not be shown if the corresponding data # value is the empty string function tem_auto_nonempty(&$value) { @@ -331,7 +340,7 @@ function tem_auto_nonempty(&$value) { return $value; } -# 'not' sections will not be shown if the corresponding data +# 'unset' sections will not be shown if the corresponding data # value is not set (opposite of default) function tem_auto_unset(&$value) { if($value === null) { @@ -352,6 +361,27 @@ function tem_auto_evenodd(&$values) { return $values; } +# 'once' sections are shown exactly once if the value is set (and not at all +# otherwise.) This is useful when an array value would otherwise cause the +# section to be displayed multiple times. +function tem_auto_once(&$value) { + if($value === null) return null; + return true; +} + +function tem_auto_once_if(&$value) { + if($value) return true; + return null; +} + +# 'once' sections are shown exactly once if php evaluates the value to false +# (and not at all otherwise.) This is useful when an array value would +# otherwise cause the section to be displayed multiple times. +function tem_auto_once_else(&$value) { + if($value) return null; + return true;; +} +